0
0
PHPprogramming~10 mins

Named arguments in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to call the function using a named argument for name.

PHP
<?php
function greet(string $name) {
    echo "Hello, $[1]!";
}
greet(name: "Alice");
?>
Drag options to blanks, or click blank then click option'
AAlice
Bgreet
Cname
Decho
Attempts:
3 left
💡 Hint
Common Mistakes
Using the function name instead of the parameter name.
Using the argument value instead of the parameter name.
2fill in blank
medium

Complete the function call using a named argument for age.

PHP
<?php
function showAge(int $age) {
    echo "Age: $[1]";
}
showAge(age: 30);
?>
Drag options to blanks, or click blank then click option'
AshowAge
Bage
C30
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using the function name instead of the parameter name.
Using the argument value instead of the parameter name.
3fill in blank
hard

Fix the error by completing the function call with the correct named argument for city.

PHP
<?php
function printCity(string $city) {
    echo "City: $[1]";
}
printCity(city: "Paris");
?>
Drag options to blanks, or click blank then click option'
Astring
BprintCity
CParis
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Using the function name instead of the parameter name.
Using the argument value instead of the parameter name.
4fill in blank
hard

Fill both blanks to call the function with named arguments for firstName and lastName.

PHP
<?php
function fullName(string $firstName, string $lastName) {
    echo "Name: $[1] $[2]";
}
fullName([1]: "John", [2]: "Doe");
?>
Drag options to blanks, or click blank then click option'
AfirstName
BlastName
CJohn
DDoe
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parameter names.
Using argument values as parameter names.
5fill in blank
hard

Fill all three blanks to call the function with named arguments for title, author, and year.

PHP
<?php
function bookInfo(string $title, string $author, int $year) {
    echo "Book: $[1], Author: $[2], Year: $[3]";
}
bookInfo([1]: "1984", [2]: "Orwell", [3]: 1949);
?>
Drag options to blanks, or click blank then click option'
Atitle
Bauthor
Cyear
Dbook
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names.
Mixing up the order of named arguments.