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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -