CodeChap
CodeChap

Reputation: 4262

Is there a nice clean way to unset from an array but return that unset value?

Something like the would be nice:

$name = unset($array['username']);

Leaving $array without a username but assigned to $name.

I'm just looking for the least complex way of doing this really.

Upvotes: 0

Views: 426

Answers (1)

aayoubi
aayoubi

Reputation: 12099

unset has void as return type.

void unset ( mixed $var [, mixed $... ] )

You can do it like this:

$name = $array['username'];
unset($array['username']);

Upvotes: 2

Related Questions