How can you define function in PHP? Create a function that will take two integers as argument and will return product of them.

This answer is restricted. Please login to view the answer of this question.

Login Now

Besides the built-in PHP functions, it is possible to create our own functions.

  • A function is a block of statements that can be used repeatedly in a program.
  • A function will not execute automatically when a page loads.
  • A function will be executed by a call to the function.

To create function in PHP, We have start with function keyword followed by the function name.

The syntax for Function Define:

function function_name( $parameters ){
    //custom code
}


/* While calling */
function_name(  $parameters  );

Now, We make a function that will take two integers as arguments and will return the product of them.

<?php

function multiplytwonumber( int $num1, int $num2 ){
    return $num1 * $num2;
}

echo multiplytwonumber(5, 6);

The output of the above code is

30
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .