why result is 7? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html) +--- Thread: why result is 7? (/thread-31469.html) why result is 7? - El Forum - 06-20-2010 [eluser]pincs[/eluser] Code:```<?php \$i=1; echo "i=".(++\$i)+(++\$i)+(++\$i); //result 7 //but echo (++\$i)+(++\$i)+(++\$i); result is 9 ?>``` why result is 7? - El Forum - 06-20-2010 [eluser]daelsepara[/eluser] first statement: Code:`// (1) + (2) + (3) = 7` second statement: Code:`// (2) + (3) + (4) = 9` why result is 7? - El Forum - 06-20-2010 [eluser]InsiteFX[/eluser] Operator Precedence - SEE the PHP Manual. InsiteFX why result is 7? - El Forum - 06-20-2010 [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``` why result is 7? - El Forum - 06-21-2010 [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