Home > Backend Development > PHP Tutorial > About the mystery of self-increment and self-decrement operations in PHP_PHP Tutorial

About the mystery of self-increment and self-decrement operations in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:17:24
Original
1093 people have browsed it

About the secrets of self-increment and self-decrement operations in PHP

First look at an interview question:

    $a = 1;
    $b = &$a;

    if ($b == $a++)
        echo "true";
    else
        echo "false";
Copy after login

First, a variable $a is created and the value is set to 1;

Then, a variable $b is created and used as a reference to $a;

The last judgment statement contains two opcodes: POST_INC and IS_EQUAL. The first thing to execute is the return first and then increment statement (POST_INC), which returns 1 first, and then $a increments to 2, because $b is a reference to $a, and $b is also 2. Then the comparison statement (IS_EQUAL) is executed, because the value of $b is 2 and the return value of $a++ is 1, so they are not equal.

Similar interview questions include:

    $a = 1;
    $b = &$a;

    $b = $a++;
    
    echo "a: $a; b: $b";
Copy after login



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/892832.htmlTechArticleAbout the mystery of self-increment and self-decrement operations in PHP, first look at an interview question: $a = 1; $ b = $a; if ($b == $a++) echo "true"; else echo "false"; First, a variable $a is created and...
Related labels:
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