Reputation: 29880
For example:
$array = array('f', 'b');
assign($foo, $bar, $array);
// now $foo = 'f' and $bar = 'b'
Does something like this exist in the PHP language? I have never needed something like this before and cannot find anything that will do this.
I just wanted to make sure before I write the function myself - I don't want to write something that already exists within the language.
Upvotes: 0
Views: 239
Reputation: 132011
list ($foo, $bar) = $array;
list()
is something like the opposite of array()
and its a language construct. Its especially important to know, that even if its listed in the functions reference of the manual (list()
), it isn't, because no function is writeable.
Upvotes: 3
Reputation: 25755
you can use php's list()
function
$array = array('f', 'b');
list($foo, $bar) = $array;
now it is
$foo = 'f' and $bar = 'b';
Upvotes: 1