Answer me.

Source: Internet
Author: User
$a = 1;
$b = $a + $a + +;
Echo $b;
$a = 1;
$b = $a + $a + $a + +;
Echo $b;
Why are all the outputs 3?


Reply to discussion (solution)

http://cn2.php.net/manual/zh/language.operators.increment.php
$a = 3 * 3 5; (3 * 3)% 5 = 4
$a = true? 0:true? 1:2; (true? 0:true)? 1:2 = 2

$a = 1;
$b = 2;
$a = $b + = 3; $a = ($b + = 3), $a = 5, $b = 5

Mixing + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>

http://cn2.php.net/manual/zh/language.operators.increment.php
!--? php
$a = 3 * 3% 5; (3 * 3)% 5 = 4
$a = true? 0:true 1:2;//(true? 0:true)? 1:2 = 2

$a = 1;
$b = 2;
$a = $b + = 3;//$a = ($b + = 3) $a = 5, $b = 5

//mixing + + + produces undefined behavior
$a = 1;
Echo + + $a + $a + +;//May print 4 or 5
?>
Do you have anything to do with my question?

Officially, there is no definition of the result when the + + + + + is present at the same time.

Now in the version of PHP 5.3.x windows, your result is 3, $a 2


http://cn2.php.net/manual/zh/ language.operators.increment.php
!--? php
$a = 3 * 3 5;//(3 * 3)% 5 = 4
$a = true? 0:true? 1:2; (true? 0:true)? 1:2 = 2

$a = 1;
$b = 2;
$a = $b + = 3;//$a = ($b + = 3) $a = 5, $b = 5

//mixing + + + produces undefined behavior
$a = 1;
Echo + + $a + $a + +;//May print 4 or 5
?>
Do you have anything to do with my question?


http://cn2.php.net/manual/zh/language.operators.increment.php
$a = 3 * 3 5; (3 * 3)% 5 = 4
$a = true? 0:true? 1:2; (true? 0:true)? 1:2 = 2

$a = 1;
$b = 2;
$a = $b + = 3; $a = ($b + = 3), $a = 5, $b = 5

Mixing + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>
Does this answer have anything to do with my question?
The above is an extract from the PHP access document, the Scarlet Letter is the answer to your question.

Mixing + + + produces undefined behavior
Mix + + and + Generate indeterminate behavior

So there's no need to discuss it anymore.

I'm sorry I didn't look carefully

The authorities have already said that there is no definition of the result when the + + + + is present at the same time.

Now the PHP 5.3.x Windows version of your results is 3, $a to 2



http://cn2.php.net/manual/zh/language.operators.increment.php
$a = 3 * 3 5; (3 * 3)% 5 = 4
$a = true? 0:true? 1:2; (true? 0:true)? 1:2 = 2

$a = 1;
$b = 2;
$a = $b + = 3; $a = ($b + = 3), $a = 5, $b = 5

Mixing + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>
Does this answer have anything to do with my question?

  • 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.