什么是PHP运算符%?如何在实际示例中使用它? [英] What is the PHP operator % and how do I use it in real-world examples?
本文介绍了什么是PHP运算符%?如何在实际示例中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对PHP运算符%
的详细解释是什么?
What is the explanation for PHP's operator %
in full detail?
包括示例会很好!
推荐答案
它是模运算符,它给出除法的整数余数 例如
It's the modulus operator, which gives the integer remainder of a division e.g.
7 / 2 = 3.5 // 3 remainder 1
7 % 2 = 1 // the remainder
一个明显的现实世界例子正在计算一个数字是奇数还是偶数
Obvious real world example is working out whether a number is odd or even
如果((($ n%2)== 0)这个数字是偶数,否则很奇怪...当您想以不同的颜色显示表格中的其他行时很有用
if (($n % 2) == 0) the number is even, else it's odd... useful when you want to show alternate rows in a table in different colours
这篇关于什么是PHP运算符%?如何在实际示例中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文