Calculations

Function to multiply two numbers in PHP

Function to multiply two numbers in PHP

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

Find multiplication of two numbers

Function to multiply two numbers

Find multiplication of two numbers using function – #1

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

 

Find multiplication of two numbers using function – #2

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 addition of two numbers

PHP subtraction of two numbers

PHP addition of two numbers using function

PHP subtraction of two numbers using function

PHP program to multiply two numbers
PHP dividing two numbers: PHP program
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

20 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago