Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 22, 2021 03:32 am GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To