Complete the code to set a default value for the parameter.
<?php function greet($name = [1]) { echo "Hello, $name!"; } greet(); ?>
The default value for the parameter $name is set to the string "Guest". This means if no argument is passed, it will greet "Guest".
Complete the code to call the function with the default parameter.
<?php function sayAge($age = [1]) { echo "Age is $age."; } sayAge(); ?>
The function sayAge has a default parameter value of 18. Calling sayAge() without arguments will print "Age is 18."
Fix the error in the function definition by completing the default parameter value.
<?php function multiply($num, $factor = [1]) { return $num * $factor; } echo multiply(5); ?>
The default value for $factor should be a number without quotes to correctly multiply.
Fill both blanks to create a function with two parameters, one with a default value.
<?php function describe($item, $color = [1]) { echo "The $item is $color."; } describe([2]); ?>
The function describe has a default color "red". Calling describe("apple") prints "The apple is red."
Fill all three blanks to define a function with default parameters and call it correctly.
<?php function order($food = [1], $drink = [2]) { echo "Order: $food and $drink."; } order([3]); ?>
The function order has default values "pizza" and "water". Calling order("burger") overrides the first default and uses the second default.