I have dynamic array like this $color[0] = 'Red' $color[1] = 'Green' $color[2] = 'Blue' $color[3] = 'black' $color[4] = 'white' I want to move "black" to first index of the array and move "Red" to down at index 2. How can i do this? Any code snippet or article?
Here's php's array functions. I don't think there is a way to do it without some logic within a function. http://www.php.net/manual/en/ref.array.php
This should work function moveToFirst(&$array, $str) { $key=array_search($str,$array); if($key) unset($array[$key]); array_unshift($array,$str); return $array; } PHP: I also tried a function that reorders the whole array with a foreach but this one was a lot faster.