php arithmetic operators

伊谢尔伦
Release: 2016-11-24 13:37:05
Original
1124 people have browsed it

Remember the basic math knowledge you learned in school? Just like them.

Arithmetic Operator

Example Name Result

-$a Negative value of $a.

$a + $b Addition The sum of $a and $b.

$a - $b Subtraction The difference between $a and $b.

$a * $b Multiplication The product of $a and $b.

$a / $b Division quotient of $a divided by $b.

$a % $b Modulo The remainder of $a divided by $b.

The division operator always returns a floating point number. The only exception is that both operands are integers (or integers converted from strings) and are exactly divisible, in which case it returns an integer.

The operands of the modulo operator will be converted to integers (except for the decimal part) before operation.

The result of the modulo operator % is the same as the sign (positive or negative sign) of the dividend. That is, the result of $a % $b has the same sign as $a. For example:

<?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
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!