Last active
December 28, 2015 06:29
-
-
Save arlaneenalra/7457767 to your computer and use it in GitHub Desktop.
A crude array_splice that preserves keys.
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_preserve ($input, $offset, $length, $replacement) { | |
$keys = array_keys($input); | |
$values = array_values($input); | |
array_splice($keys, $offset, $length, array_keys($replacement)); | |
array_splice($values, $offset, $length, array_values($replacement)); | |
return array_combine($keys, $values); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment