算術運算子是 PHP 程式語言中的運算子類型之一。算術運算子可以方便地進行許多數學計算,以執行不同類型的程式來簡化我們解決問題的任務。算術運算子只能與數值/數字一起使用來執行算術運算,例如加法(+)、減法(-)、乘法(x)、除法(/)、模數(%)、指數(**)(1 st 2 次方nd 數)。
廣告 該類別中的熱門課程 PHP 開發人員 - 專業化 | 8 門課程系列 | 3次模擬測驗開始您的免費軟體開發課程
網頁開發、程式語言、軟體測試及其他
算術運算子使用兩個數值/數字來執行加法(+)、減法(-)、乘法(x)、除法(/)、模數(%)、指數(**)(1 st 數字的2nd 數字)。
加法是 PHP 程式語言的算術運算子之一。需要至少兩個/更多數值/數字相加。
代碼:
<?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/>"; ?>
輸出:
減法是 PHP 程式語言的算術運算子之一。它需要至少兩個/更多數值/數字來相減。
代碼:
<?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/>"; ?>
輸出:
乘法是 PHP 程式語言的算術運算子之一。它需要至少兩個/更多數值/數字才能相乘。
代碼:
<?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/>"; ?>
輸出:
除法是 PHP 程式語言的算術運算子之一。它需要至少兩個/更多數值/數字才能相除。
代碼:
<?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/>"; ?>
輸出:
模數是此程式語言的算術運算子之一。知道餘數需要至少兩個/更多數值/數字。當你將一個數字除以任何其他數字時,你只會得到數字 1 或數字 0 值作為餘數,但如果你除以一個大數字,你肯定會得到 0 值。
代碼:
<?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/>"; ?>
輸出:
求冪是此程式語言的算術運算子之一。它需要至少兩個/更多數值/數字才能知道第 1st 數字的 2nd 數字的冪。
代碼:
<?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/>"; ?>
輸出:
我希望您了解算術運算符是什麼以及如何使用這些算術運算符。我想您也了解加法(+)、減法(-)、乘法(x)、除法(/)、模數(%)、求冪(**)(1st 數字到2第 數的冪)。
以上是PHP 中的算術運算符的詳細內容。更多資訊請關注PHP中文網其他相關文章!