PHP Parameterized Functions are the PHP functions with parameters. PHP Parameterized functions are a piece of code that can be used repeatedly in a PHP program. Any number of parameters can be passed inside a parameterized function after the name of the function, inside the parentheses.
Syntax:
function functionName() { code to be executed; } |
Example 1: Parameterized Function used with a single argument
<!DOCTYPE html> <html> <body> <?php function website($languagename) { echo "$languagename.<br>"; } website("PHP"); website("Jquery"); website("HTML"); website("Javascript"); ?> </body> </html> |
Output
PHP. Jquery. HTML. Javascript. |
Example 2: Parameterized function used for ADDITION (Two arguments passed; function returns a value)
<!DOCTYPE html> <html> <body> <?php function sum($x, $y) { $z = $x + $y; return $z; } echo "Sum of 4575 and 1890 = " . sum(4575,1890) . "<br>"; echo "Sum of 5677 and 1783 = " . sum(5677,1783) . "<br>"; echo "Sum of 268879 and 49879080 = " . sum(268879,49879080); ?> </body> </html> |
Output
Sum of 4575 and 1890 = 6465 Sum of 5677 and 1783 = 7460 Sum of 268879 and 49879080 = 50147959 |