An Interest In:
Web News this Week
- March 26, 2024
- March 25, 2024
- March 24, 2024
- March 23, 2024
- March 22, 2024
- March 21, 2024
- March 20, 2024
December 22, 2021 03:32 am GMT
Original Link: https://dev.to/irfankhan177/php-operator-4ke9
Php Operator
Arithmetic Operators
Arithmetic operators work with numeric values to perform common arithmetical operations.
<?php$num1=8;$num2=6;//Additionecho $num1+$num2; //14//Substractionecho $num1-$num2; //2//Multiplicationecho $num1*$num2; //48//Divisionecho $num1/$num2 ; //1.33333333?>
Modulus
The modulus operator, represented by the % sign, returns the remainder of the division of the first operand by the second operand:
<?php$x=14;$y=3;echo $x%$y //2?>
Increment & Decrement
The increment operators are used to increment a variable's value.
The decrement operators are used to decrement a variable's value.
<?php$x++; // equivalent to $x = $x+1;$x--; // equivalent to $x = $x-1;?>
Increment and decrement operators either precede or follow a variable.
<?php$x++; // post-increment $x--; // post-decrement ++$x; // pre-increment --$x; // pre-decrement?>
The difference is that the post-increment returns the original value before it changes the variable, while the pre-increment changes the variable first and then returns the value.
Example:
<?php$a = 2; $b = $a++; // $a=3, $b=2$a = 2; $b = ++$a; // $a=3, $b=3?>
Original Link: https://dev.to/irfankhan177/php-operator-4ke9
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To