php - PHP 是否支持数组解构?

标签 php

我的意思是这样的:

$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 within foreach), as an alternative to the existing list() syntax, which is still supported.

关于php - PHP 是否支持数组解构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54893278/

相关文章:

php基于浏览器上传视频到youtube channel apiv3

php - Woocommerce - 从错误消息中删除 'Billing' 字

php - PHP 和 .htaccess 重定向之间的区别

PHP MySQL 按日和月排序

php - 我应该把一个库放在一个不能通过 Composer 访问的 Yii 项目中的什么地方?

php - Windows 上的 Google App Engine PHP

php - 如何将内容整齐地保存到文件中?

php - 在 javascript 中使用 php 数组?

php - 按组排序(查询生成器)

php - 根据 mysql_fetch_array 结果更改按钮?