2015-11-25 103 views
2

由于PHP的行为,我有点沮丧。 为什么PHP解释这样我的代码:总结回声php

echo "We has over " . 2500 + 500 . " employees over the world"; // 500 employees over the world 
+2

运算符优先级....因为'+'和'.'具有相同的优先级,并且都是左联合的,你实际上在做'((“我们已经结束了.2500)+ 500)。 “世界各地的员工”' –

+0

用圆括号括起计算。运算符优先规则! – Thamilan

+0

谢谢,马克。现在我明白了:) –

回答

0

你也可以改变上面的代码为:

<?php 
$sum=2500 + 500; 
echo "We has over " . $sum . " employees over the world"; 

?> 
+0

我很有趣,为什么PHP会剪切字符串。 –

+1

查看我对你的问题的评论,解释为什么 –