PHP 将数组的值赋值给一组变量

经常需要将一个字符串分割成一组值,然后赋值给不同的变量。

逐行赋值非常繁琐,于是查了一下 PHP 中是否有类似 python 中 a, b = (a, b) 的操作。

果然有

$info = array('coffee', 'brown', 'caffeine');
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.
";

list 这个关键字,是专门为这个操作而生的。

可以忽略一个值。

list($drink, , $power) = $info;
原文地址:https://www.cnblogs.com/sgm4231/p/10196712.html