4

This is applicable in 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

1 Answer 1

2

There is no intention for such syntax. You can use any expression or assignment instead of an array element in PHP. PHP will calculate the result of expression and puts the result in array.

 $b=1;
 $a=[$b,$b+2,$b+$a,$a++,$a>$b,$c=$a+$b]
Sign up to request clarification or add additional context in comments.

1 Comment

Should that be restricted so that many errors could have been prevented :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.