Php program to execute the default argument function

A simple Php program¬†to execute the default argument function. Constant expressions must be used as default arguments. Variables or function calls aren’t allowed. As default parameters, PHP allows you to use a scalar value, an array, or null. Because they don’t need to be given to the method, these default values are also known as optional arguments. I’ve recently noticed this type of code being used wrongly quite a bit, so I thought I’d write a post about it.

<?php declare(strict_types=1);?>
<!DOCTYPE html>
<html>
<body>
<?php
function setHeight(int $minheight = 10)
{
echo "The height is $minheight <br>";
}
setHeight(100);
setHeight();
setHeight(10);
setHeight(5);
?>
</body>
</html>

 

Output:

The height is 100
The height is 10
The height is 10
The height is 5