In this tutorial, we will discuss the concept of Function to multiply two numbers in PHP
In this topic, we are going to learn how to write a program to multiplication of two numbers using user-defined function in PHP programming language
In this program, the user declare two integer variables $x and $y as parameters of the user defined function. Then two numbers are multiplied using multiplications(-) operator. finally when the user call the function with passing argument, the result is displayed on the screen
Program 1
<?php //php script //function definition with parameter function mulTwoNumbers($x, $y) { return $x * $y; //calculate the product of two numbers using minus operator //and return value } //Calling the function with argument to print result echo "The multiplication of 25 and 35: ".mulTwoNumbers(25,35); echo "<br>"; echo "The multiplication of 15 and -30: ".mulTwoNumbers(15,-30); echo "<br>"; echo "The multiplication of -10 and -11: ".mulTwoNumbers(-10,-11); echo "<br>"; //exit php ?>
When the above code is executed, it produces the following result
The multiplication of 25 and 35: 875 The multiplication of 15 and -30: -450 The multiplication of -10 and -11: 110
In this program, the user declare two integer variables $x and $y as parameters of the user defined function. Then two numbers are multiplied using multiplication(*) operator. finally when the user call the function with passing argument, the result is displayed on the screen
Program 2
<?php //php script //function definition 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 20 and 30: "; echo mulTwoNumbers(20,30); echo "<br>"; echo "The product of 20 and 12: "; echo mulTwoNumbers(20,12); echo "<br>"; echo "The product of 10 and -10: "; echo mulTwoNumbers(10,-10); echo "<br>"; //exit php ?>
When the above code is executed, it produces the following result
The product of 20 and 30: 600 The product of 20 and 12: 240 The product of 10 and -10: -100
Similar post
Java program to multiplication of two numbers
C program to multiplication of two numbers
C++ program to multiplication of two numbers
Python program to multiplication of two numbers
Java program to multiplication two floating-point numbers
C program to multiplication two floating-point numbers
C++ program to multiplication two floating-point numbers
Python program to multiplication two floating-point numbers
Java program to multiply two numbers using methods
C program to multiply two numbers using function
C++ program to multiply two numbers using function
Python program to multiply two numbers function
PHP subtraction of two numbers
How to find reverse number using method In this article, we will discuss the concept…
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…