In php, I would like to have the ability to re-order an associative array by moving elements to certain positions in the array. Not necessary a sort, just a re-ordering of
A lot of difficult methods here :) In fact, you can exploit the preserve keys feature of array_slice().
$new_element = array('new_key' => 'value');
// if needed, find the insertion index by key
$index = array_search('key to search', array_keys($old_array));
// add element at index (note the last array_slice argument)
$new_array = array_slice($old_array, 0, $index+1, true) + $new_element + array_slice($old_array, $index+1, null, true);