我的意思是这样的:
$arr = ["1", "2", "3"];
$one;
$two;
$three;
$new = [$one, $two, $three] = $arr;
结果我应该得到:
$one = 1;
$two = 2;
$three = 3;
我试过了,它在 PHP 7.3.2 中有效:
var_dump($one); // returns 1
最佳答案
确实,它被列为 new feature in PHP 7.1 :
The shorthand array syntax (
[]
) may now be used to destructure arrays for assignments (including withinforeach
), as an alternative to the existinglist()
syntax, which is still supported.
关于php - PHP 是否支持数组解构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54893278/