tags:

views:

67

answers:

1

In perl I can write

($var1, $var2, $var3) = split(/:/, "foo:bar:blarg")

to split a string by colon and assign each array element to $var1, $var2 and $var3. Is there a similar syntax for this in php? I have to use the variables in a lot of my code so I want them to have meaningful names, and writing variable assignment code like

$array = split(/:/, "foo:bar:blarg");
$var1 = $array[0];
$var2 = $array[1];
//etc

is tedious when i have to do this a lot.

+6  A: 

PHP has the list language construct to do that.

list($var1, $var2, $var3) = split(":", "foo:bar:blarg");
Gumbo
just what I need. thanks!
Charles Ma