php parameter type code example
Example 1: php functions parameters
// functions require 'function' keyword
// separate the parameters with a comma
function addFunction($num1, $num2) {
$sum = $num1 + $num2;
echo "Sum of the two numbers is : $sum";
}
addFunction(1, 2); // echoes: Sum of the two numbers is : 3
Example 2: php 7.1 functions parameters with "?"
function sayHello(?string $name) {
echo "Hello " . $name . PHP_EOL;
}
sayHello(null); // Hello
sayHello("John"); //Hello John