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
10 ways tousing function-PHP program

PHP program to subtract two numbers using function-PHP program

Posted on July 7, 2022July 18, 2022

Table of Contents

  • PHP program to subtract two numbers using function
    • Code to difference  of two numbers in PHP
      • Subtraction of two numbers using function  – #1
      • Subtraction of two numbers using function  – #2
    • Related

PHP program to subtract two numbers using function

In this article, we will discuss the concept of PHP program to subtract two numbers using function

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

Code to difference  of two numbers in PHP

Subtraction of two numbers using function  – #1

Program 1

  • Start PHP script
  • Declare two integer variable as parameter
  • Calculate difference of given two numbers and return value
  • Calling the function with argument
  • Display result on the screen
  • Exit PHP

In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen

<html>
<head>
<title> Subtraction of two numbers</title>
</head>
<body>
<?php
//function definition
function subTwoNumbers($x, $y)
{
  return $x - $y;
}
//Calling the function and print result
echo "Difference of 200 and 30: ".subTwoNumbers(200,30);
echo "<br>";
echo "Difference of 150 and 550: ".subTwoNumbers(150,550);
echo "<br>";
echo "Difference of 100 and -40: ".subTwoNumbers(100,-40);
echo "<br>";
?>
</body>
</html>

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

Difference of 200 and 30: 170
Difference of 150 and 550: -400
Difference of 100 and -40: 140

 

Subtraction of two numbers using function  – #2

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

Program 1

  • Start PHP script
  • Declare and initiates two integer variable as parameter
  • Calculate difference of given two numbers and return value
  • Calling the function and Display result on the screen
  • Exit PHP

In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen

<head>
<title> Subtraction of two numbers</title>
</head>
<body>
<h3>PHP Subtract two numbers using function</h3>
<?php
//function definition
function subTwoNumbers($x, $y)
{
  $sub=$x - $y;
  return $sub;
  echo $sub;
}
//Calling the function and print result
echo "The Difference of 10 and 300: ";
echo subTwoNumbers(10,300);
echo "<br>";
echo "The Difference of 200 and 120: ";
echo subTwoNumbers(200,120);
echo "<br>";
echo "The Difference of 100 and -200: ";
echo subTwoNumbers(100,-200);
echo "<br>";
?>
</body>
</html>

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

PHP Subtract two numbers using function

The Difference of 10 and 300: -290
The Difference of 200 and 120: 80
The Difference of 100 and -200: 300

 

Suggested post

Subtract two number in Java language

Subtract two number in C language

Subtract two number in C++ language

Subtract two number in Python language

 

Sum of two integers in C#

Sum of two integers using function in C#

Sum of two floating point numbers in C#

 

Addition two number  in Java language

Addition two number in C language

Addition two number  in C++ language

Addition two number in Python language

 

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes