What\'s the most elegant way in PHP to move an array element chosen by key to the first position?
Input:
$arr[0]=0; $arr[1]=1; $arr[2]=2; .... $arr[n
Something like this should work. Check if the array key exists, get its value, then unset it, then use array_unshift to create the item again and place it at the beginning.
unset
array_unshift
if(in_array($key, $arr)) { $value = $arr[$key]; unset($arr[$key]); array_unshift($arr, $value); }