How to use function with parameter in PHP
In this article, I will explain how the function with parameter can be used in PHP.
Function with parameter in PHP
- In function with parameter, pass parameters inside a function.
- In function with parameter, you can pass as many as parameters your like. These parameters work like variables inside your function.
- In function with parameter, a parameter appears with the parentheses "( )"
Syntax
function functionname(parameters)
{
code to be executed;
}
|
Example
The following example takes two integer parameters and add them together and then print total.
<html>
<head>
<title>Function with Parameters</title>
</head>
<body>
<h2 style="color: steelblue;">Function with Parameters Loop example</h2>
<?php
function add($num1, $num2)
{
$total = $num1 + $num2;
echo "Sum of the two numbers is : $total";
}
add(90, 10);
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here