php - Get array values between two position -
i have example array:
$list = array(40, 22, 60, 50);
and:
$start = 40; $end = 60;
i values between $start , $end (can $start , $end). example receive:
array(40, 22, 60);
if:
$start = 22; $end = 60;
then receive:
array(22, 60);
and if:
$list = array(40, 22, 60, 50, 100, 200, 70);
and:
$start = 22; $end = 200;
i receive: array(22, 60, 50, 100, 200);
how can make it?
you loop through array, there's way:
$list = array(40, 22, 60, 50, 100, 200, 70); $start = 22; $end = 200; $start_position = array_search($start, $list); $end_position = array_search($end, $list); $values = array_slice($list, $start_position, $end_position - $start_position + 1);
Comments
Post a Comment