Skip to content

Instantly share code, notes, and snippets.

@jasonreposa
Created January 19, 2012 14:49
Show Gist options
  • Save jasonreposa/1640416 to your computer and use it in GitHub Desktop.
Save jasonreposa/1640416 to your computer and use it in GitHub Desktop.
Array splice with preserve keys
function array_psplice(&$array, $offset = 0, $length = 1) {
$return = array_slice($array, $offset, $length, true);
foreach ($return as $key => $value) {
unset($array[$key]);
}
return $return;
}
@jasonreposa
Copy link
Author

I love that this is still useful! I haven't programmed PHP in at least 6 years. 👍

@omarmojica
Copy link

Sweet solutions in 2021!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment