Search code examples
phpvbamoduloternary

What does it mean? expr1 = expr2 Mod expr3 = 0


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>]


Solution

  • 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