Tribe__Main::array_insert_before_key( $key, $source_array, $insert_array )
Insert an array immediately before a specified key within another array.
Contents
Parameters
- $key
-
(Required)
- $source_array
-
(Required)
- $insert_array
-
(Required)
Return
(array)
Source
File: src/Tribe/Main.php
public static function array_insert_before_key( $key, $source_array, $insert_array ) {
if ( array_key_exists( $key, $source_array ) ) {
$position = array_search( $key, array_keys( $source_array ) );
$source_array = array_slice( $source_array, 0, $position, true ) + $insert_array + array_slice( $source_array, $position, null, true );
} else {
// If no key is found, then add it to the end of the array.
$source_array += $insert_array;
}
return $source_array;
}