I do not see a built-in function for this, but you can easily create your own.
function array_remove(array &$arr, $key) { if (array_key_exists($key, $arr)) { $val = $arr[$key]; unset($arr[$key]); return $val; } return null; }
You can use it with any array, for example, $_SESSION :
return array_remove($_SESSION, 'AFTER_LOGIN_TARGET');
Short and sweet
In PHP 7+, you can use the union operator of zeros to greatly reduce this feature. You don't even need isset() !
function array_remove(array &$arr, $key) { $val = $arr[$key] ?? null; unset($arr[$key]); return $val; }
David harkness
source share