Skip to content

Instantly share code, notes, and snippets.

@gnanasekaran08
Created March 23, 2021 05:32
Show Gist options
  • Save gnanasekaran08/cd219837263337197229117f5132913c to your computer and use it in GitHub Desktop.
Save gnanasekaran08/cd219837263337197229117f5132913c to your computer and use it in GitHub Desktop.
Splice Associative Array method
$args = splice_associative_array($args, $index, $content);
if (!function_exists('splice_associative_array')) {
function splice_associative_array($original_data, $position, $replacement_array)
{
/**
* Appending the $replacement_array array in $original_data array, set the $position ad -1.
* Add the $replacement_array array in top of the $original_data array, then set the $position as 0.
*
*/
$data = array_slice($original_data, 0, $position, true) +
$replacement_array +
array_slice($original_data, 0, count($original_data), true);
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment