Created
September 24, 2013 19:28
-
-
Save kfriend/6690005 to your computer and use it in GitHub Desktop.
PHP: array_splice_assoc() helper
This file contains hidden or 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
<?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