Ben benzer bir yöntemle geldi ve array_splice_key olarak ayarlamak @ Luxian cevabı benzer. https://gist.github.com/4499117
/**
* Insert another array into an associative array after the supplied key
*
* @param string $key
* The key of the array you want to pivot around
* @param array $source_array
* The 'original' source array
* @param array $insert_array
* The 'new' associative array to merge in by the key
*
* @return array $modified_array
* The resulting merged arrays
*/
function array_splice_after_key( $key, $source_array, $insert_array ) {
return array_splice_key( $key, $source_array, $insert_array );
}
/**
* Insert another array into an associative array before the supplied key
*
* @param string $key
* The key of the array you want to pivot around
* @param array $source_array
* The 'original' source array
* @param array $insert_array
* The 'new' associative array to merge in by the key
*
* @return array $modified_array
* The resulting merged arrays
*/
function array_splice_before_key( $key, $source_array, $insert_array ) {
return array_splice_key( $key, $source_array, $insert_array, -1 );
}
/**
* Insert another array into an associative array around a given key
*
* @param string $key
* The key of the array you want to pivot around
* @param array $source_array
* The 'original' source array
* @param array $insert_array
* The 'new' associative array to merge in by the key
* @param int $direction
* Where to insert the new array relative to given $position by $key
* Allowed values: positive or negative numbers - default is 1 (insert after $key)
*
* @return array $modified_array
* The resulting merged arrays
*/
function array_splice_key( $key, $source_array, $insert_array, $direction = 1 ){
$position = array_search( $key, array_keys( $source_array ) ) + $direction;
// setup the return with the source array
$modified_array = $source_array;
if( count($source_array) < $position && $position != 0 ) {
// push one or more elements onto the end of array
array_push( $modified_array, $insert_array );
} else if ( $position < 0 ){
// prepend one or more elements to the beginning of an array
array_unshift( $modified_array, $insert_array );
} else {
$modified_array = array_slice($source_array, 0, $position, true) +
$insert_array +
array_slice($source_array, $position, NULL, true);
}
return $modified_array;
}