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

Source: Internet
Author: User
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

Analytical:

1: The && and assignment operator "=" has a priority of && precedence, but the accents is not written in $a and $b first and then = $c, so understanding is equivalent to 1= $c, and 1= $c such a notation is wrong

2: This kind of alternative writing is correctly understood in the following way:

if ($a) {$b = $c}, that is, if $ A is true, execute the assignment statement $b = $c; otherwise this assignment statement is not executed, so the result is not difficult to understand

The above describes a "heterogeneous" syntax in PHP: $a && $b = $c, including aspects of the content, want to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.