CodeIgniter Forums

Full Version: why result is 7?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

[eluser]daelsepara[/eluser]
first statement:

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

second statement:

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

El Forum

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

InsiteFX

El Forum

[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

El Forum

[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