Recall & Review
beginner
What is a function in PHP?
A function is a reusable block of code that performs a specific task. You can call it whenever you need that task done.
Click to reveal answer
beginner
How do you declare a function in PHP?
Use the <code>function</code> keyword, followed by the function name and parentheses. Inside curly braces, write the code to run when the function is called.<br><br>Example:<br><code>function greet() { echo 'Hello!'; }</code>Click to reveal answer
beginner
How do you call a function in PHP?
Write the function name followed by parentheses. If the function needs inputs, put them inside the parentheses.<br><br>Example:<br>
greet();Click to reveal answer
beginner
What happens if you call a function that has parameters?
You must provide the required values (arguments) inside the parentheses when calling the function. These values are used inside the function.<br><br>Example:<br><code>function sayHello($name) { echo "Hello, $name!"; }<br>sayHello('Alice');</code>Click to reveal answer
beginner
Can a function return a value in PHP? How?
Yes, a function can send back a value using the <code>return</code> keyword. This lets you use the result elsewhere.<br><br>Example:<br><code>function add($a, $b) { return $a + $b; }<br>$sum = add(3, 4);</code>Click to reveal answer
Which keyword is used to declare a function in PHP?
✗ Incorrect
In PHP, the keyword
function is used to declare a function.How do you call a function named
greet in PHP?✗ Incorrect
To call a function, just write its name followed by parentheses:
greet();What will this code output?<br>
function sayHi() { echo 'Hi!'; }<br>sayHi();✗ Incorrect
The function
sayHi prints 'Hi!' when called.What is needed when calling a function that requires parameters?
✗ Incorrect
You must provide the required arguments inside parentheses when calling a function with parameters.
What does the
return keyword do in a function?✗ Incorrect
The
return keyword sends a value back to the place where the function was called.Explain how to declare and call a function in PHP with an example.
Think about the basic structure and how you use the function after declaring it.
You got /5 concepts.
Describe how parameters and return values work in PHP functions.
Consider how data goes into and comes out of a function.
You got /4 concepts.