Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created August 9, 2014 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/3926708fa3332cae4d95 to your computer and use it in GitHub Desktop.
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
/**
* 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