0
0
PHPprogramming~10 mins

Function declaration and calling 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 declare a function named greet.

PHP
<?php
function [1]() {
    echo "Hello!";
}
?>
Drag options to blanks, or click blank then click option'
Ahello
BprintMessage
CsayHello
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than the one called.
Forgetting to write the function keyword.
2fill in blank
medium

Complete the code to call the function greet.

PHP
<?php
greet[1];
?>
Drag options to blanks, or click blank then click option'
A()
B{}
C[]
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function without parentheses.
Using curly braces or square brackets instead of parentheses.
3fill in blank
hard

Fix the error in the function declaration to accept one parameter named name.

PHP
<?php
function greet([1]) {
    echo "Hello, $name!";
}
?>
Drag options to blanks, or click blank then click option'
A$name
B*name
C&name
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign in the parameter.
Using pointer or reference symbols incorrectly.
4fill in blank
hard

Fill both blanks to call the greet function with the argument 'Alice'.

PHP
<?php
greet([1][2]);
?>
Drag options to blanks, or click blank then click option'
AAlice
B"Alice"
C'Alice'
DAlice()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the argument without quotes.
Using a function call instead of a string.
5fill in blank
hard

Fill all three blanks to declare a function named add that takes two parameters and returns their sum.

PHP
<?php
function [1]([2], [3]) {
    return $a + $b;
}
?>
Drag options to blanks, or click blank then click option'
Aadd
B$a
C$b
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names without $.
Using a different function name than add.