Skip to content

Instantly share code, notes, and snippets.

@waelio
Last active December 29, 2015 13:14
Show Gist options
  • Save waelio/a6ba0eef1ae9036155f7 to your computer and use it in GitHub Desktop.
Save waelio/a6ba0eef1ae9036155f7 to your computer and use it in GitHub Desktop.
Inject an array with another array a certainposition
<?php
/**
* @param array $needle
* @param array $haystack
* @param $position
* @return array
*/
function inject_this_array($needle=array(),$haystack=array(),$position){
$new_holder1 = array_slice($haystack, 0, $position, true);
$new_holder2 = array_slice($haystack, $position, count($haystack)-1,true);
array_push($new_holder1, $needle);
return $new_holder1 + $new_holder2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment