PHP basic synta...LOGIN

PHP basic syntax arithmetic operations

Arithmetic operators are the vast majority of knowledge we have learned in elementary school:

##*Multiply sign, multiply by $x * $y/division sign, divided by $x / $y%Remainder is also called modulus and modulus$x % $y
<?php

$x = 5;

$y = 6;
//5+6为11
echo $x + $y;

?>
<?php

$x = 20;

$y = 15;
//20 -15 为5
echo $x - $y;

?>
<?php

$x = 20;

$y = 15;
//20乘以15结果为300
echo $x * $y;

?>
<?php

$x = 10;

$y = 5;
//10除以5 结果为2
echo $x / $y;

?>
<?php

$x = 10;

$y = 3;
//$x 不能整除3,得到的余数为1,所以结果输出为1
echo $x % $y;

?>
SymbolExplanationExample
+plus sign#$x + $y
-Minus sign$x - $y
Similar to what we have learned in mathematics, there is also a priority: multiplication and division first, then addition and subtraction. If you want to change the priority more explicitly, use () [parentheses] to enclose the value you want to take precedence.


Next Section

<?php $x = 10; $y = 3; //$x 不能整除3,得到的余数为1,所以结果输出为1 echo $x % $y; ?>
submitReset Code
ChapterCourseware