Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php syntax $a = $b = 1;

Tags:

syntax

php

Is

$a = 1;
$b = $a;

equal to writing this?

$a = $b = 1;

Will the second example always put 1 as value to both $a and $b, even if $a and $b already has a value assigned to them?

like image 291
Kristian Rafteseth Avatar asked Oct 24 '25 19:10

Kristian Rafteseth


1 Answers

Yes, PHP will put 1 in $b then put $b value in $a, i.e. 1.

There is no ambiguity as the first assignment is $b = 1, the next is $a = $b.

like image 134
Déjà vu Avatar answered Oct 26 '25 09:10

Déjà vu