% is an operator module . Thus, % 2 is the remainder after dividing by two, therefore either 0 (in the case if $id was even) or 1 (in the case of $id was odd).
The expression !($id % 2) uses automatic conversion to a boolean value (in which 0 represents false and all non-zero represents true) and negates the result. Thus, the result of this expression is true if $id was even and false if it was odd. It also determines what echo prints there. Apparently an even value for $id means success.
Somewhat more complicated, but perhaps easier to understand, is how to write the above statement:
if ($id % 2 == 0) echo "{'id':$id,'success':1}"; else echo "{'id':$id,'success':0,'error':'Could not delete subscriber'}";
But it spoils all the pleasures with the help of the ternary operator. However, I would not write the condition as !($id%2) , but rather as ($id % 2 != 0) . Bad integers for Boolean values ββsometimes make it difficult to diagnose errors :-)
source share