Heim > Backend-Entwicklung > PHP-Tutorial > Arithmetische Operatoren in PHP

Arithmetische Operatoren in PHP

王林
Freigeben: 2024-08-29 12:38:37
Original
708 Leute haben es durchsucht

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 Tests

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Explanation of Arithmetic operators in PHP

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 ).

1. Addition (+)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

2. Subtraction (-)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

3. Multiplication (x)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

4. Division (/)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

5. Modulus (%)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

6. Exponentiation (**)

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/>";
?>
Nach dem Login kopieren

Output:

Arithmetische Operatoren in PHP

Conclusion

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!

Verwandte Etiketten:
php
Quelle:php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage