PHP Program to Perform Arithmetic Operations Last Updated : 20 Nov, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report This article will show you how to perform arithmetic operations in PHP. The arithmetic operators are used to perform simple mathematical operations like addition, subtraction, multiplication, etc. Arithmetic OperatorsOperator Name Syntax Description Addition $x + $y The addition operator is used to add both operands. Subtraction $x - $y The subtraction operator is used to subtract the second operand from the first operand. Multiplication $x * $y The multiplication operator is used to multiply both operands. Division $x / $y The division operator is used to divide the first operand by second operand. Exponentiation $x ** $y The exponentiation operator is used to calculate exponent of first operands to the power second operand. Modulus $x % $y The modulus operator is used to calculate the remainder of the operand. Example 1: This example will show the implementation of arithmetic operator. PHP <?php $x = 10; $y = 4; // Performs Arithmetic operations // and display the result echo($x + $y) . "\n"; echo($x - $y) . "\n"; echo($x * $y) . "\n"; echo($x / $y) . "\n"; echo($x ** $y) . "\n"; echo($x % $y); ?> Output14 6 40 2.5 10000 2 Example 2: This example will show the implementation of arithmetic operators using switch case. PHP <?php $x = 10; $y = 4; $operator = "*"; switch ($operator) { case "+": echo $x + $y; break; case "-": echo $x - $y; break; case "*": echo $x * $y; break; case "/": echo $x / $y; break; case "**": echo $x ** $y; break; case "%": echo $x % $y; break; default: echo "Incorrect Operator"; break; } ?> Output40 Comment More infoAdvertise with us Next Article How to Convert Number to Character Array in PHP ? B blalverma92 Follow Improve Article Tags : PHP PHP-Operators Geeks Premier League 2023 Similar Reads Program to print multiplication table of any number in PHP In this article, we will see how to print the multiplication table of any given number using PHP. To make the multiplication table, first, we get a number input from the user and then use for loop to display the multiplication table. We use HTML and PHP to display the multiplication table. The HTML 1 min read PHP program to print an arithmetic progression series using inbuilt functions We have to print an arithmetic progressive series in PHP, between two given numbers a and b both including, a given common arithmetic difference of d. Examples: Input : $a = 200, $b = 250, $d = 10 Output : 200, 210, 220, 230, 240, 250 Input : $a = 10, $b = 100, $d = 20 Output : 10, 30, 50, 70, 90Th 2 min read Write a program to display Reverse of any number in PHP ? Write a program to reverse the digits of an integer. Examples : Input : num = 12345 Output: 54321 Input : num = 876 Output: 678 It can be achieved using Iterative way or Recursive Way Iterative Method: Algorithm: Input: num (1) Initialize rev_num = 0 (2) Loop while num > 0 (a) Multiply rev_num by 2 min read PHP program to swap two numbers Integer values can be stored in a variable in PHP. It is easy to store and modify and swap these integer values using various mentioned approaches: Using a temporary variable: The value of the first number is stored in the temporary variable. This value is then replaced by the value of the second nu 4 min read How to Convert Number to Character Array in PHP ? Given a number, the task is to convert numbers to character arrays in PHP. It is a common operation when you need to manipulate or access individual digits of a number. This can be particularly useful in situations where you need to perform operations on the digits of a number, such as digital root 3 min read PHP - MYSQL : sum() operation Problem Statement: In this article, we are going to perform sum() aggregate operation on our database using PHP with xampp server. So we are considering the food_order database and perform database sum() operation. Requirements: xampp Introduction: PHP stands for hypertext preprocessor which is a se 3 min read Like