what is the difference between these functions ? and why we are assigning an empty value to a function parameter ?
function prints($var = '') {
echo $var; }
function prin($var) {
echo $var; }
Both prints the same result.
what will happen if we assign an empty value to a function parameter ?
The first function has a default value for its first parameter. That means that parameter doesn’t need to be specified when calling that function.
So you can call the first function without the parameter like this:
And the default value for the first parameter is used. But when calling the second function the parameter needs to given:
If you call it without that parameter (
prin()), you’ll get a warning like: