Created
December 28, 2017 15:55
-
-
Save dg01d/2fafc1c8877c062696d38e513a355218 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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