A 'heterogeneous' syntax in php: $a && $b = $c;, php heterogeneity_PHP tutorial

WBOY
Release: 2016-07-11 10:36:20
Original
934 people have browsed it

A "heterogeneous" syntax in php: $a && $b = $c;, a "heterogeneous" syntax in php

A "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 that && has a higher priority, but in the red writing method, $a and $b do not do the AND operation first and then =$c. This understanding is equivalent to 1=$c, And the way of writing 1=$c is wrong 2: The correct way to understand this alternative writing method is: if($a){$b = $c}, that is, if $a 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1140578.htmlTechArticleA heterogeneous syntax in php: $a $b = $c;, a "heterogeneous" syntax in php heterogeneous 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!