What does the percent sign mean in PHP?

后端 未结 6 1150
生来不讨喜
生来不讨喜 2020-12-03 04:25

What exactly does this mean?

$number = ( 3 - 2 + 7 ) % 7;
6条回答
  •  孤街浪徒
    2020-12-03 04:56

    % means modulus.

    Modulus is the fancy name for "remainder after divide" in mathematics.

    (numerator) mod (denominator) = (remainder)
    

    In PHP

    
    

    In this case, this script will echo

    6 is (13 mod 7).
    

    Where $r is for the remainder (answer), $n for the numerator and $d for the denominator. The modulus operator is commonly used in public-key cryptography due to its special characteristic as a one-way function.

提交回复
热议问题