Skip to content

Instantly share code, notes, and snippets.

@dg01d
Created December 28, 2017 15:55
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 dg01d/2fafc1c8877c062696d38e513a355218 to your computer and use it in GitHub Desktop.
Save dg01d/2fafc1c8877c062696d38e513a355218 to your computer and use it in GitHub Desktop.
/**
* Returns a value from an array and deletes
* the key=>value pair like python's s.pop['i']
*
* @param array $arr The array to be searched
* @param $key The search term
* @return The $value mapped to $key or null
*/
function key_pop(array &$arr, $key) {
if (array_key_exists($key, $arr)) {
$val = $arr[$key];
unset($arr[$key]);
return $val;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment