Heim > Artikel > Backend-Entwicklung > Arithmetische Operatoren in PHP
Arithmetic operators are one of the types of operators in the PHP programming language. The arithmetic operators are handy for many mathematical calculations to do different types of programs to ease our problem-solving tasks. Arithmetic operators can be used only with the numerical values/numbers to perform arithmetic operations like Addition (+), Subtraction (-), Multiplication (x), Division (/), Modulus (%), Exponentiation (**)(1st number to the power of 2nd number ).
ADVERTISEMENT Popular Course in this category PHP DEVELOPER - Specialization | 8 Course Series | 3 Mock TestsStart Your Free Software Development Course
Web development, programming languages, Software testing & others
The Arithmetic operators are used two numeric values/numbers to perform Addition (+), Subtraction (-), Multiplication (x), Division (/), Modulus (%), Exponentiation (**)(1st number to the power of 2nd number ).
The Addition is one of the Arithmetic operators of the PHP programming language. It requires at least two/ more numerical values/numbers to add.
Code:
<?php $pavan = 25; $kumar = 24; $sake = $pavan + $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The sum of the two variables :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 23; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $sake + $p1 ; echo "The Sum of the three Variables :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 44; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $pavan1 + $k1; echo "The Sum of the four Variables :: $s1"; echo "<br/>"; ?>
Output:
Subtraction is one of the Arithmetic operators of the PHP programming language. It requires at least two/ more numerical values/numbers to subtract.
Code:
<?php $pavan = 25; $kumar = 24; $sake = $pavan - $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The substraction of the two variables :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 23; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $sake - $p1 ; echo "The Substraction of the three Variables :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 44; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $k1 - $pavan1; echo "The Substraction of the four Variables $pavan, $kumar, $p1, $k1, $pavan1 :: $s1"; echo "<br/>"; ?>
Output:
Multiplication is one of the Arithmetic operators of the PHP programming language. It requires at least two/ more numerical values/numbers to multiply.
Code:
<?php $pavan = 25; $kumar = 24; $sake = $pavan * $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The multiplicaation of the two variables :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 23; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $sake * $p1 ; echo "The Multiplication of the three Variables :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 44; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $pavan1 * $k1; echo "The Multiplication of the four Variables :: $s1"; echo "<br/>"; ?>
Output:
The division is one of the Arithmetic operators of the PHP programming language. It requires at least two/ more numerical values/numbers to divide.
Code:
<?php $pavan = 250; $kumar = 5; $sake = $pavan / $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The Division of the two variables :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 5; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $sake / $p1 ; echo "The Division of the three Variables :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 5; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $k1/$pavan1; echo "The Division of the four Variables :: $s1"; echo "<br/>"; ?>
Output:
Modulus is one of the Arithmetic operators of this programming language. Knowing the remainder value requires at least two/ more numerical values/numbers. You will get only number 1 or number 0 values as the remainder when you divide a number with any other number, but if you divide with a big number, you will definitely get a 0 value for that.
Code:
<?php $pavan = 250; $kumar = 5; $sake = $pavan % $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The remainder by dividing $pavan with $kumar :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 3; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $pavan%$p1 ; echo "The remainder by dividing $pavan with $p1 :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 5; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $pavan%$pavan1; echo "The remainder by dividing $pavan with $pavan1 :: $s1"; echo "<br/>"; ?>
Output:
Exponentiation is one of the Arithmetic operators of this programming language. It requires at least two/ more numerical values/numbers to know the 1st number to the power of the 2nd number.
Code:
<?php $pavan = 2; $kumar = 5; $sake = $pavan ** $kumar; echo "First Variable Value : $pavan"; echo "<br/>"; echo "Second Variable Value : $kumar"; echo "<br/>"; echo "The result by getting the power of $pavan with $kumar :: "; echo $sake; echo "<br/>"; echo "<hr/>"; $p1 = 3; echo "Third Variable Value : $p1"; echo "<br/>"; $k1 = $pavan**$p1 ; echo "The result by getting the power of $pavan with $p1 :: $k1"; echo "<br/>"; echo "<hr/>"; $pavan1 = 5; echo "Fourth Variable Value : $pavan1"; echo "<br/>"; $s1 = $pavan**$pavan1; echo "The result by getting the power of $pavan with $pavan1 :: $s1"; echo "<br/>"; ?>
Output:
I hope you understand what the Arithmetic operators are and how to use those Arithmetic operators. I think you also understood what is meant by Addition (+), Subtraction (-), Multiplication (x), Division (/), Modulus (%), Exponentiation (**)(1st number to the power of 2nd number ).
Das obige ist der detaillierte Inhalt vonArithmetische Operatoren in PHP. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!