简体   繁体   中英

Is there a shorthand way to assign a group of variables to each of the values of an array in php?

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.

PHP具有list语言构造来做到这一点。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM