PHP arithmetic operators

Source: Internet
Author: User
Tags arithmetic arithmetic operators

1, +: Plus

2,-: minus

3, *: Multiply

4,/: except

5,%: modulo, get the remainder of the division of two numbers

6. + +: Self-added

7 、--: Self-reduction

8, + +: Left add

9.-=: Left minus

10. *=: Left Multiply

11./=: Left apart

12,%=: Left to take the mold

Example: Programming a PHP program to determine whether two numbers are divisible .

<?php

$a = 100;
$b = 3;
$c = $a% $b;
if ($c) {
echo "is not divisible! ";
}else{
echo "Can divide! ";
}
?>

Examples of PHP self-addition and self-subtraction operators :

Example 1:

<?php

$a = 90;

$a + +; Equivalent to $a= $a +1;

echo $a;

$b = 80;

$b--; Equivalent to $b= $b-1;

echo ' <br/> '. $b;

?>

Example 2:

<?php

$a = 90;

$b = $a + +; After + +, first use the value, then add 1. The statement is equivalent to the $b= $a; $a = $a +1;

Echo $b; Output 90

echo ' <br/> '. $a; Output 91

?>

Example 3:

<?php

$a = 90;

$b =++ $a; First + +, add 1 First, then use the value. The statement is equivalent to the $a= $a +1; $b = $a;

Echo $b; Output 91

echo ' <br/> '. $a; Output 91

?>

examples of Zoga :

<?php

$a = 90;

$a +=90; Equivalent to $a= $a +90;

echo $a; Output 180

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.