Skip to content

Instantly share code, notes, and snippets.

@kfriend
Created September 24, 2013 19:28
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 kfriend/6690005 to your computer and use it in GitHub Desktop.
Save kfriend/6690005 to your computer and use it in GitHub Desktop.
PHP: array_splice_assoc() helper
<?php
function array_splice_assoc($array, $key, $replacement = array())
{
// Get numeric offset of the key to remove
$offset = array_search($key, array_keys($array));
if (!is_int($offset)) return $array;
unset($array[$key]);
return array_slice($array, 0, $offset, true)
+ (array) $replacement
+ array_slice($array, $offset, null, true);
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment