산술 연산자

학교에서 기초 산수를 기억하십니까? 이것들은 그것들처럼 작동합니다.

산술 연산자

Example Name Result
+$a Identity Conversion of $a to int or float as appropriate.
-$a Negation Opposite of $a.
$a + $b Addition Sum of $a and $b.
$a - $b Subtraction Difference of $a and $b.
$a * $b Multiplication Product of $a and $b.
$a / $b Division Quotient of $a and $b.
$a % $b Modulo Remainder of $a divided by $b.
$a ** $b Exponentiation Result of raising $a to the $b'th power.

나누기 연산자("/")는 두 피연산자가 정수(또는 정수로 변환되는 문자열)가 아니고 숫자가 균등하게 나눌 수 있는 경우가 아니면 정수 값을 반환하는 부동 소수점 값을 반환합니다. 정수 나누기에 대해서는 intdiv()를 참조하십시오.

모듈로의 피연산자는 처리 전에 int로 변환됩니다. 부동 소수점 모듈로의 경우 fmod()를 참조하십시오.

모듈로 연산자 %의 결과는 피제수와 동일한 부호를 갖습니다. 즉, $a % $b의 결과는 $a와 동일한 부호를 갖습니다. 예를 들어:

                  
<?php

echo (5 % 3)."\n";           // prints 2
echo (5 % -3)."\n";          // prints 2
echo (-5 % 3)."\n";          // prints -2
echo (-5 % -3)."\n";         // prints -2

?>
                  
                
기타