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 multiply two numbers using function

PHP multiply two numbers using function

Posted on July 11, 2022July 18, 2022

Table of Contents

  • PHP multiply two numbers using function
    • Code to find product of two numbers in PHP
      • Product of two numbers using function  – #1
      • Product of two numbers using function  – #2

PHP multiply two numbers using function

In this article, we will discuss the concept of PHP multiply two numbers using function

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

Code to find product of two numbers in PHP

Product of two numbers using function  – #1

Program 1

  • Start PHP script
  • Declare two integer variable as parameter
  • Calculate product of given two numbers and return the value to main
  • Calling the function with passing 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> product of two numbers</title>
</head>
<body>
<h3>Multiply two number using function</h3>
<?php //php script
//function definition with parameter
function mulTwoNumbers($x, $y)
{
  return $x * $y;
  //calculate the product of two numbers using function
  //and return the product of given number
}
//Calling the function with argument to print result
echo "The product of 5 and 12: ".mulTwoNumbers(5,12);
echo "<br>";
echo "The product of 5 and -10: ".mulTwoNumbers(5,-10);
echo "<br>";
echo "The product of -12 and -13: ".mulTwoNumbers(-12,-13);
echo "<br>";
//exit php
?>
</body>
</html>

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

Multiply two number using function

The product of 5 and 12: 60
The product of 5 and -10: -50
The product of -12 and -13: 156

 

Product of two numbers using function  – #2

Program 2

  • Start PHP script
  • Declare two integer variable as parameter
  • Calculate product of given two numbers and return value to main
  • 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> product of two numbers</title>
</head>
<body>
<h3>Multiply two number using function</h3>
<?php //php script
//function definition with parameter
function mulTwoNumbers($x, $y)
{
  $mul=$x * $y;
  //calculate product of two numbers 
  //using multiplicaion(*) operator
  return $mul;//return the result to main
  echo $mul;//print the result when calling the function
}

//Calling the function and print result
echo "The product of 15 and 10: ";
echo mulTwoNumbers(15,10);
echo "<br>";
echo "The product of 25 and 10: ";
echo mulTwoNumbers(25,10);
echo "<br>";
echo "The product of 15 and -12: ";
echo mulTwoNumbers(15,-12);
echo "<br>";
//exit php
?>

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

Multiply two number using function

The product of 15 and 10: 150
The product of 25 and 10: 250
The product of 15 and -12: -180

 

 

Similar post

Java program to multiply two numbers

C++ program to multiply two numbers

C program to multiply two numbers

Python program to multiply two numbers

 

Java program to multiply two floating-point numbers

C++ program to multiply two floating-point numbers

C program to multiply two floating-point numbers

Python program to multiply two floating-point numbers

 

PHP addition of two numbers

PHP addition of two numbers using function

PHP subtraction of two numbers

PHP subtraction of two numbers using function

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