Q & A-php Tutorial

Source: Internet
Author: User
Q & a $ a = 1;
$ B = $ a + $ a ++;
Echo $ B;
$ A = 1;
$ B = $ a + $ a ++;
Echo $ B;
Why are all output 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 ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>

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 ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?

The official website has already said that when both ++ and ++ exist, there is no definition of the result.

In php 5.3.x windows, your result is 3, and $ a is 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 ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to 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 ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?
The above is extracted from the php access document. The Red Letter is the answer to your question.

Mixing ++ and + produces undefined behavior
Mixed ++ and ++ produce uncertain behaviors

So there is no need to discuss it.

Sorry, I didn't take it seriously.

The official website has already said that when both ++ and ++ exist, there is no definition of the result.

In php 5.3.x windows, your result is 3, and $ a is 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 ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to 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.