If there is no division in this PHP code, where the remainder should come from?

Hello, I am very new to PHP, just learning some basic stuff. In this following condition-reaction code, there is a remainder inside the condition, yet I don’t recognize any division action like: 4\2=%2 ==0, so I can’t understand what is written there in the original form. Would thank you for an explanation:

  $my_var = 6;
  if ($my_var < 0 || $my_var > 10 && $my_var %2 == 0) 
      print 'my_var is > 2 or < 0 AND is even';
      print 'my_var is between 0 and 10 OR is odd';    

$a % $b Modulus Remainder of $a divided by $b.


This reads as - divide $my_var by 2 and get the remainder. The % indicates that a division is required but that it is the remainder that is to be returned instead of the result of the division.

1 Like

Thank you felgall, your clarification helped me.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.