+ + + And a little doubt

Source: Internet
Author: User
For more information about ++ and & amp;, this post was last edited by yinjie_1984 from 2014-11-1508: 22: 22 & lt ;? Php $ a1; $ B & $ a; $ B $ a ++; the second sentence of $ a and $ B means that B points to the address of; the third sentence means adding 1 to the value of a after use, so $ b1; the key is that I don't know about ++ and & a little doubt.

This post was last edited by yinjie_1984 at 08:22:22

$ A = 1;
$ B = & $;
$ B = $ a ++;

// Calculate $ a and $ B
In the second sentence, B also points to the address of;
In the third sentence, the value of a is added with 1, so $ B = 1;
The key is that I don't know $ a ++ later. I don't mean to add 1 after using it, so now $ a = 2;
But the address of $ B is the same as the address of a. isn't the address of $ B equal to 2? Or is $ a ++ not executed in the third sentence? The answer to this question is $ a and $ B is 1;
For example
$ A = 1;
$ B = $ a ++;
?>
This is not $ B = 1, $ a = 2
A little dizzy...
------ Solution ----------------------
$a = 1;
$b = $a++;
var_dump($a, $b);
/*
int(2)
int(1)
*/

$a = 1;
$b = &$a;
$a++;
var_dump($a, $b);
/*
int(2)
int(2)
*/

$a = 1;
$b = &$a;
$b = $a++;
var_dump($a, $b);
/*
int(1)
int(1)
*/

For $ B = $ a ++;
Assign the value 1 of $ a to $ B, but the priority of ++ is higher than =, so the value is not assigned first, but ++, therefore, the value of $ a is 2 (because $ B is a reference of $ a, the value of $ B is also 2)
Then assign a value. The value of $ B is equal to 1.
Because $ B is a reference of $ a, $ a is changed back to 1.

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.