why result is 7?

#1
[eluser]pincs[/eluser]
Code:
<?php
$i=1;
echo "i=".(++$i)+(++$i)+(++$i); //result 7
//but echo (++$i)+(++$i)+(++$i); result is 9
?>

#2
[eluser]daelsepara[/eluser]
first statement:

Code:
// (1) + (2) + (3) = 7

second statement:

Code:
// (2) + (3) + (4) = 9

#3
[eluser]InsiteFX[/eluser]
Operator Precedence - SEE the PHP Manual.

InsiteFX

#4
[eluser]pincs[/eluser]
[quote author="daelsepara" date="1277110704"]first statement:

Code:
// (1) + (2) + (3) = 7

second statement:

Code:
// (2) + (3) + (4) = 9
[/quote]


i think first statment like this:2+3+4
Code:
echo "i=".(++$i);//2
echo "i=".(++$i)+12;//12
echo "i=".(++$i)+(++$i);//3

#5
[eluser]InsiteFX[/eluser]
Operator Precedence - SEE the PHP Manual.

Code:
<?php
$i = 1;
// notice here I wrapped the increments with
// a beginning and ending parentheses.
// parentheses may be used to force precedence
echo "i=".((++$i)+(++$i)+(++$i)); //result 9
//echo (++$i)+(++$i)+(++$i); //result is 9
?>

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.