When using PHP, I find myself writing code like this a lot:
$target = $_SESSION[AFTER_LOGIN_TARGET];
unset($_SESSION[AFTER_LOGIN_TARGET]);
return $target;
In Python, there is a dict.pop
method that would let me do something similar in one statement, without a temporary variable:
return session.pop(AFTER_LOGIN_TARGET)
Is there a similar function or trick in PHP?
Why about a helper function? Something like that:
So if you call
you have what you asked for (try it a little, I haven't used php for many times :-])
I don't see a built-in function for this, but you can easily create your own.
You can use it with any array, e.g.
$_SESSION
:I think what you are looking for is array_slice()