PHP 官方针对 7.1 的新提案(RFC):简化数组的解构方式

2016-04-08 10:05:58 +08:00
 stabc

或许 7.1 版本之后,你可以这样:

[$a, $b, $c] = [1, 2, 3];

详情: https://www.hackerhot.com/s/34/php

2665 次点击
所在节点    PHP
3 条回复
hardway
2016-04-08 22:40:19 +08:00
少打"list"四个字而已

list($a,$b,$c)=[1,2,3];
jfcherng
2016-04-08 23:45:27 +08:00
@hardway

// This is not allowed:
list([$a, $b], [$c, $d]) = [[1, 2], [3, 4]];

// This is also not allowed:
[list($a, $b), list($c, $d)] = [[1, 2], [3, 4]];

// This, however, is allowed:
[[$a, $b], [$c, $d]] = [[1, 2], [3, 4]];
jfcherng
2016-04-08 23:46:45 +08:00
foreach ($points as ["x" => $x, "y" => $y]) {
var_dump($x, $y);
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/269460

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX