Table of Contents
A 'heterogeneous' syntax in PHP: $a && $b = $c;
Jul 09, 2016 am 09:08 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
$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 do not do the AND operation first and then =$c. This understanding is equivalent to 1= $c, and 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
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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5060533 fails to install in Windows 10?
4 weeks ago
By DDD
Dune: Awakening - Where To Get Insulated Fabric
4 weeks ago
By Jack chen
Gmail Login: How to Sign Up, Sign In, or Sign Out of Gmail - MiniTool
1 months ago
By Jack chen
How to fix KB5060999 fails to install in Windows 11?
3 weeks ago
By DDD
Guild Guide In Tainted Grail: The Fall Of Avalon
4 weeks ago
By Jack chen

Hot Tools

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)
