# PHP引數化函式

PHP引數化函式是帶有引數的函式。 您可以在函式中傳遞任意數量的引數。 這些傳遞的引數作為函式中的變數。

## PHP引數化範例1

``````<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>引數加法和減法範例</title>
</head>
<body>
<?php
//Adding two numbers
function add(\$x, \$y) {
\$sum = \$x + \$y;
echo "Sum of two numbers is = \$sum <br><br>";
}
add(300, 700);

//Subtracting two numbers
function sub(\$x, \$y) {
\$diff = \$x - \$y;
echo "Difference between two numbers is = \$diff";
}
sub(1000, 500);
?>
</body>
</html>
``````

## PHP引數化範例2

``````<?php
//add() function with two parameter
function add(\$x,\$y)
{
\$sum=\$x+\$y;
echo "Sum = \$sum <br><br>";
}
//sub() function with two parameter
function sub(\$x,\$y)
{
\$sub=\$x-\$y;
echo "Diff = \$sub <br><br>";
}
//call function, get  two argument through input box and click on add or sub button
if(isset(\$_POST['add']))
{
//call add() function
add(\$_POST['first'],\$_POST['second']);
}
if(isset(\$_POST['sub']))
{
//call add() function
sub(\$_POST['first'],\$_POST['second']);
}
?>
<form method="post">
Enter first number: <input type="number" name="first"/><br><br>
Enter second number: <input type="number" name="second"/><br><br>
<input type="submit" name="add" value="ADDITION"/>
<input type="submit" name="sub" value="SUBTRACTION"/>
</form>
``````