In PHP, arithmetic operators are used to perform mathematical operations on numerical values. These operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%), as well as increment (++) and decrement (--) operators.
Operator | Name | Description |
---|---|---|
+$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 |
Operator precedence determines the order in which the arithmetic operations are evaluated. For example, multiplication and division have a higher precedence than addition and subtraction. To change the order of operations, parentheses can be used.
Overall, arithmetic operators in PHP are essential for performing mathematical operations and manipulating numerical data within PHP programs.
<?php //Arithmetic Operators //Identity $a="10"; echo "<br>".gettype($a); $a=+"10"; echo "<br>".gettype($a); //Negation $a=40; echo "<br>A Value : ".$a; echo "<br>A Value : ".-$a; //Addition $a=123; $b=10; echo "<br> Total : ".$a+$b; //Subtraction echo "<br> Diffrence : ".$a-$b; //Multiplication echo "<br> Multiply : ".$a*$b; //Division echo "<br> Division : ".$a/$b; //Modulo echo "<br> Modulo : ".$a%$b; //Exponentiation $base=2; //2*2*2*2 $power=4; echo "<br> Exponentiation : ".$base**$power; ?>
This code demonstrates the use of arithmetic operators in PHP to perform mathematical operations. Here is a breakdown of each section of the code:
Overall, this code provides a good introduction to the different arithmetic operators in PHP and how they can be used to perform mathematical operations on numerical values.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions