Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
PHP Addition of two numbers: PHP program

PHP Addition of two numbers: PHP program

Posted on June 28, 2022July 6, 2022

Table of Contents

  • PHP Addition of two numbers: PHP program
    • Code to sum  of two numbers in PHP
      •  Addition of two numbers in PHP
      •  Division of two numbers in PHP using third  variable
      •  Division of two numbers in PHP -using form
      • Division of two numbers in PHP -without + operator

PHP Addition of two numbers: PHP program

In this article, we will discuss the concept of PHP Addition of two numbers

In this post, we are going to learn how to write a program to find  addition of two numbers in PHP language

Code to sum  of two numbers in PHP

 Addition of two numbers in PHP

In this code, we are going to learn how to write a program to addition of two numbers in PHP  programming language

Program 1

  • Start PHP script
  • Declare and initiates two integer variable
  • Calculate sum of given two numbers
  • Display result on the screen
  • Exit PHP

In this program, the user initiates the values to variables and calculates the sum of the given values using plus(+) operator

<?php
$num1=5;
$num2=10;
$sum=$num1+$num2;
  echo "Sum: ",$sum;
?>

When the above code is executed it produces the following  result

Sum: 15

 

 Division of two numbers in PHP using third  variable

In this program, the user initiates the values to variables and calculates the sum off the given numbers using plus(+) operator .Then the result is assigned to third variable (msg) .finally the result is displayed on the screen.

Program  2

  • Start PHP script
  • Declare and initiates two integer variable
  • Calculate sum of given two numbers
  • Assign the result to third variable
  • Display result on the screen
<?php
$x=5;
$y=10;
$sum=$x+$y;
$msg = 'Sum of x and y:' ;
print($msg.$sum);
?>

When the above code is executed it produces the following  result

Sum of x+y = 35

 

 Division of two numbers in PHP -using form

In this program, the user is entered the values to variables using form(the program Asks input from the user to enter the form) and calculates the sum off the given numbers using plus(+) operator .Then the result is assigned to third variable (sum) .finally the result is displayed on the screen.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

Program 3

<html>
<head>
  <title>Sum of given  two numbers </title>
  </head>
  <body>
  <h3>Calculate  addition of given numbers</h3>

<form method="post">  
Enter 1st value:  
<input type="number" name="number1" /><br><br>  
Enter 2nd value:  
<input type="number" name="number2" /><br><br>  
<input  type="submit" name="submit" value="Add">  
</form>  



<?php  
    if(isset($_POST['submit']))  
    {  
        $number1 = $_POST['number1'];  
        $number2 = $_POST['number2'];  
        $sum =  $number1+$number2;     
echo "The sum of $number1 and $number2 is: ".$sum;   
}  
?> 

</body>
</html>

When the above code is executed it produces the following  result

Division of two numbers in PHP -without + operator

In this program, the user is entered the values to variables (the program Asks input from the user) and calculates the sum off the given values using without plus(+) operator .And then the result is displayed on the screen.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

Program 4

<html>
<head>
  <title>Addition of given  two numbers </title>
  </head>
  <body>
  <h3>Calculate  addition  of two numbers </h3>

<form>  
<b>Enter 1st number for sum:</b>
<input type="number" name="number1" /> <br> <br>
<b>Enter 2nd number for sum:  </b>
<input type="number" name="number2" />  </br>
<input  type="submit" name="submit" value="Sum">  
</form>  

</body>

<?php  
  @$number1 = $_GET['number1'];  
  @$number2 = $_GET['number2'];  
  for($i=1; $i<=$number2; $i++) 
  {
  $number1++;
    }			
echo "Sum of given two numbers".$number1
;     
?>  

When  the   above  code is  executed, it produces the  following result.

 

Enter number to form

 

click the sum button to  find  addition

PHP Addition of two numbers: PHP program
Addition of two numbers:

 

Suggested for you

Java program to add two numbers

C program to add two numbers

C++ program to add two numbers

Python program to add two numbers

 

Write a program to sum of prime numbers 1 to n in Java language

Write a program to sum of prime numbers 1 to n in C language

Write a program to sum of prime numbers 1 to n in C++ language

Write a program to sum of prime numbers 1 to n in Python  language

 

Write a program to sum of natural numbers 1 to n in Java language

Write a program to sum of prime numbers 1 to n in C language

Write a program to sum of prime numbers 1 to n in C++ language

Write a program to sum of prime numbers 1 to n in Python  language

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes