In this tutorial, we will discuss the concept of PHP subtracting two numbers-PHP program
In this topic, we are going to learn how to write a program to subtract two numbers in PHP programming language
In this program, the user declare two integer variables $x and $y. Then two numbers are subtracted using minus(-) operator. finally the result is displayed on the screen
Program 1
<?php $num1=30; $num2=15; $sum=$num1-$num2; echo "Difference: ".$sum; ?>
When the above code is executed, it produces the following result
Difference: 15
In this program, the user asked to enter two numbers(by passing input value to form). Then two numbers are subtracted using + operator and the result is displayed on the screen
Program 2
<html> <body> <form method = "post"> Enter 1st number <input type = "number" name="number1"/><br><br> Enter 2nd number <input type = "number" name="number2"/><br><br> <input type = "submit" name="submit" value="Sub"/><br> </form> <?php if(isset($_POST['submit'])) { $number1=$_POST['number1']; $number2=$_POST['number2']; $sub=$number1 - $number2; echo "The Difference of $number1 and $number2 is: ".$sub; } ?> </body> </html>
When the above code is executed, it produces the following result
In this program, the user asked to enter two numbers(by passing input value to form). Then two numbers are added using without + operator and the result is displayed on the screen
Program 3
<body> <form> Enter 1st number <input type = "number" name="number1"/><br><br> Enter 2nd number <input type = "number" name="number2"/><br><br> <input type = "submit" name="submit" value="Sub"/><br> </form> </body> <?php @$number1=$_GET['number1']; @$number2=$_GET['number2']; for($i=1; $i<=$number2; $i++){ $number1--; } echo "Difference is: ".$number1; ?>
When the above code is executed, it produces the following result
Suggested for you
Subtraction of two numbers in Java language
Subtraction of two numbers in C Language
Subtraction of two numbers in C++ Language
Subtraction of two numbers in Python Language
Subtraction of two numbers using method in Java language
Subtraction of two numbers using function in C Language
Subtraction of two numbers using function in C++ Language
Subtraction of two numbers using function in Python Language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…