views:

201

answers:

2

Most languages make it easy to take an array like [1, 2, 3] and assign those values to variables a, b, and c with a single command. For example, in Perl you can do

($a, $b, $c) = (1, 2, 3);

What's the corresponding trick in PHP?

[Thanks so much for the lightning fast answer! I know this is a trivial question but all the obvious google queries didn't turn up the answer so this is my attempt to fix that.]

+6  A: 

Use list():

list($a, $b, $c) = $someArray;
Ignacio Vazquez-Abrams
wahaha, you're faster:D
silent
Ha, figures PHP has an entire language construct, complete with a special reserved word, for this. Thanks, btw!
dreeves
+4  A: 

Use list

$arr = array(1,2,3);
list($a, $b, $c) = $arr;
silent