0
0
PHPprogramming~10 mins

Why functions are needed in PHP - Test Your Understanding

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

Complete the code to define a function named greet.

PHP
<?php
function [1]() {
    echo "Hello!";
}
?>
Drag options to blanks, or click blank then click option'
Ahello
Bgreet
CsayHello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than called.
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
Forgetting parentheses when calling a function.
3fill in blank
hard

Fix the error in the function definition by completing the code.

PHP
<?php
function greet[1] {
    echo "Hello!";
}
?>
Drag options to blanks, or click blank then click option'
A[]
B{}
C()
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses in function definitions.
4fill in blank
hard

Fill both blanks to create a function that takes a name and prints a greeting.

PHP
<?php
function greet([1]) {
    echo "Hello, " . [2] . "!";
}
?>
Drag options to blanks, or click blank then click option'
A$name
Bname
C$person
Dperson
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the dollar sign in parameter names.
5fill in blank
hard

Fill all four blanks to create a function that returns the sum of two numbers.

PHP
<?php
function add([1], [2]) {
    return [3] + [4];
}
?>
Drag options to blanks, or click blank then click option'
A$a
B$b
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names or missing dollar signs.