user965748 user965748 - 1 year ago 215
PHP Question

Move array item with certain key to the first position in an array, PHP

What's the most elegant way in PHP to move an array element chosen by key to the first position?





Answer Source

Use array_unshift:

$new_value = $arr[n];
array_unshift($arr, $new_value);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download