Created
August 9, 2014 16:09
-
-
Save hellofromtonya/3926708fa3332cae4d95 to your computer and use it in GitHub Desktop.
Adds an associative array into the specific position within the original associative array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add an associative array into any position within the | |
* original associative array | |
* | |
* @since 1.0.0 | |
* | |
* @param array $original_array Original Associative array | |
* @param array $array_to_insert Associative array to insert into the | |
* original | |
* @param integer $insert_position Position (starting at index 0) to | |
* insert the new array into the original | |
* @return array Amended array | |
*/ | |
function insert_array_into_associatve_array($original_array, $array_to_insert, $insert_position) | |
{ | |
$end = array_splice($original_array, $insert_position); | |
$start = array_splice($original_array, 0, $insert_position); | |
return array_merge($start, $array_to_insert, $end); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment