A 'heterogeneous' syntax in PHP: $a && $b = $c;
Jul 28, 2016 am 08:27 AMA "heterogeneous" syntax in php: $a && $b = $c;
$a = 1;
$b = 2;
$c = 3;
$a && $b = $c;
echo "a:$a";
echo "b:$b";
echo "c:$c";
This is
a:1
b:3
c:3
$a = 0;
$b = 2;
$c = 3;
$a && $b = $c;
echo "a:$a";
echo "b:$b ";
echo "c:$c";
This is
a:0
b:2
c:3
Analysis:
1: The priority of && and the assignment operator "=" is && has a higher priority, but in the red writing method, $a and $b are not ANDed first and then =$c. This understanding is equivalent to 1=$c, and 1=$c is wrong to write
2: The correct way to understand this alternative way of writing is:
if($a){$b = $c}, that is, if $a If it is true, the assignment statement $b = $c will be executed; otherwise, the assignment statement will not be executed, so the result is not difficult to understand
The above introduces a "heterogeneous" syntax in PHP: $a && $b = $c;, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
