简体   繁体   English

php:在数组内设置变量

[英]php : Setting variable inside array

This is applicable in php这适用于php

$a = [$a  = 2];

var_dump($a);

But what is the use of this syntax anyway ?但是这个语法有什么用呢?

IMHO this syntax could introduce more bugs in the system so i think it would be better if its restricted恕我直言,这种语法可能会在系统中引入更多错误,所以我认为如果它受到限制会更好

There is no intention for such syntax.无意使用这种语法。 You can use any expression or assignment instead of an array element in PHP.您可以使用任何表达式或赋值来代替 PHP 中的数组元素。 PHP will calculate the result of expression and puts the result in array. PHP 将计算表达式的结果并将结果放入数组。

 $b=1;
 $a=[$b,$b+2,$b+$a,$a++,$a>$b,$c=$a+$b]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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