php - Foreach iteration position -
php - Foreach iteration position -
is there way in php move iteration position in loop?
for illustration have array:
1, 2, 3, 4, 5, 6, 7, 8, 9
we have array of 1 9 want 5 placed @ end of iteration outcome this:
1 2 3 4 6 7 8 9 5
it unclear asking. anyway can obtain required output using unset
, [] operator
$element = $array[4]; unset($array[4]); $array[] = $element;
live: http://codepad.org/cwzhjjwy
if need search 5 key array_search()
:
$key = array_search(5,$array); unset($array[$key]); $array[] = 5;
php loops foreach iteration
Comments
Post a Comment