在PHP中百分号是什么意思? [英] What does the percent sign mean in PHP?
本文介绍了在PHP中百分号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这到底是什么意思?
$number = ( 3 - 2 + 7 ) % 7;
推荐答案
It's the modulus operator, as mentioned, which returns the remainder of a division operation.
示例:3%5
返回3,因为3除以5为0,其余为3.
Examples: 3%5
returns 3, as 3 divided by 5 is 0 with a remainder of 3.
5 % 10
返回5,出于相同的原因,10进入5次零次,余数为5.
5 % 10
returns 5, for the same reason, 10 goes into 5 zero times with a remainder of 5.
10 % 5
返回0,因为10除以5恰好进行2次,没有余数.
10 % 5
returns 0, as 10 divided by 5 goes exactly 2 times with no remainder.
在您发布的示例中,(3 - 2 + 7)
计算为8,得到8 % 7
,因此$number
将为1
,这是8/7的余数.
In the example you posted, (3 - 2 + 7)
works out to 8, giving you 8 % 7
, so $number
will be 1
, which is the remainder of 8/7.
这篇关于在PHP中百分号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文