这是什么意思? expr1 = expr2 模 expr3 = 0

发布于 2024-07-27 03:22:48 字数 252 浏览 2 评论 0原文

因此,我将 VBA 应用程序移植到 PHP,并遇到了这段精彩的小代码:

expr1 = expr2 Mod expr3 = 0

我认为它的行为就像三元运算符,但当我将其分解为简单的 if then 语句时,结果并不符合预期。 因此,我请求出色的 stackoverflow 社区帮助我,并用易于理解的术语来表达。 我知道通过查看其他答案我不会失望。 [/结束棕色鼻子>]

So I am porting a VBA application to PHP and ran into this wonderful little nugget of code:

expr1 = expr2 Mod expr3 = 0

I thought it was behaving like a ternary operator but when I broke it down to simple if then statements the outcome was not as expected. So I ask the brilliant stackoverflow community to help me out and put it in easy to understand terms. I know by looking at the other answers I will not be let down. [/end brown_nose>]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留蓝 2024-08-03 03:22:48

它将 expr1 分配给一个布尔值,该布尔值指示 expr2 是否可以被 expr3 整除(没有余数)。 请记住,= 在 VB 中意味着 == :D。

带有隐含括号的情况如下:

expr1 = ((expr2 Mod expr3) = 0)

It's assigning expr1 to a boolean value that indicates whether expr2 can be divided evenly (with no remainder) by expr3. Remember that = means == in VB :D.

Here's what it would look like with the implied parentheses:

expr1 = ((expr2 Mod expr3) = 0)
森林散布 2024-08-03 03:22:48

它是模数运算符:

a MOD b = remainder of a/b

在 PHP 中它是 % 符号:

a%b

请参阅此处的 php 文档

所以该行的

expr1 = expr2 Mod expr3 = 0

意思是:如果 expr2 可以除以 expr3 而没有任何余数,则 expr1 为 true:
例如:

20 MOD 5 = 0 ==> TRUE
22 MOD 5 = 2 ==> FALSE

It is the modulus operator:

a MOD b = remainder of a/b

in PHP it is the % sign:

a%b

see php documentation here

So the line

expr1 = expr2 Mod expr3 = 0

means: expr1 is true, if expr2 can be divided by expr3 without any remainders:
eg:

20 MOD 5 = 0 ==> TRUE
22 MOD 5 = 2 ==> FALSE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文