Skip to content

Instantly share code, notes, and snippets.

@jasonreposa
Created January 19, 2012 14:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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;
}
@NobleUplift
Copy link

This was the first Google result for array_splice that preserves keys. Thank you!

@ayeo
Copy link

ayeo commented Dec 6, 2018

pure and simple :)

@oooh-boi
Copy link

How the heck is that supposed to be useful?!?

@piotrkochan
Copy link

awesome! thanks

@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