Table of Contents
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
Program 1
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
Program 2
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 using function
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.