Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to display "Hello, World!" in PHP.
PHP
<?php
echo [1];
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Using echo without a semicolon.
✗ Incorrect
The echo statement outputs the string. The string must be in quotes.
2fill in blank
mediumComplete the code to start a PHP script block.
PHP
[1] echo "Welcome to PHP!"; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using short tags like which may not be enabled.
Using HTML tags like <script> instead of PHP tags.
✗ Incorrect
The correct way to start a PHP script is with <?php.
3fill in blank
hardFix the error in the PHP code to correctly declare a variable.
PHP
<?php [1] = 10; echo $number; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign before the variable name.
Trying to declare variable types explicitly.
✗ Incorrect
In PHP, variables must start with a dollar sign $.
4fill in blank
hardFill both blanks to create an array and print its first element.
PHP
<?php $fruits = array([1]); echo $fruits[2]; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index to access the first element.
Not putting strings inside quotes in the array.
✗ Incorrect
The array is created with three fruits. The first element is at index 0.
5fill in blank
hardFill all three blanks to define a function and call it.
PHP
<?php function [1]() { echo [2]; } [3](); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function name in definition and call.
Forgetting quotes around the string inside echo.
✗ Incorrect
The function is named greet, it prints a message, and then it is called by its name.