:::

23. Parameters and Arguments(參數)

Functions wouldn't be nearly as useful if they weren't able to take in some input. This is where parameters orarguments come in. These are the variables or inputs that a function uses to perform calculations.

function squareValue($number) {
  echo $number * $number;
} 

$n = 6;
squareValue($n); // echos 36

The function squareValue, above, takes one parameter, which it multiplies by itself and then echos the result. The names of the parameters themselves are used internally within the function, so they should be named something helpful.

You can also use multiple parameters as long as they are separated by commas.


:::

語系選擇