0
0
PHPprogramming~10 mins

Why PHP powers most of the web - Test Your Understanding

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

Complete the code to print "Hello, World!" in PHP.

PHP
<?php
echo [1];
?>
Drag options to blanks, or click blank then click option'
Aprint('Hello, World!')
BHello, World!
C'Hello World'
D"Hello, World!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Using print() inside echo.
2fill in blank
medium

Complete the code to declare a variable named $name with the value "PHP".

PHP
<?php
[1] = "PHP";
?>
Drag options to blanks, or click blank then click option'
Aname
B$name
Cvar name
Dlet $name
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ before the variable name.
Using JavaScript style variable declarations.
3fill in blank
hard

Fix the error in the code to correctly concatenate strings in PHP.

PHP
<?php
$name = "PHP";
echo "I love " [1] $name;
?>
Drag options to blanks, or click blank then click option'
A&
B+
C.
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of . for string concatenation.
Using commas inside echo without quotes.
4fill in blank
hard

Fill both blanks to create an associative array with keys 'language' and 'year'.

PHP
<?php
$info = array([1] => "PHP", [2] => 1995);
?>
Drag options to blanks, or click blank then click option'
A"language"
Blanguage
C"year"
Dyear
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around keys.
Using variables instead of strings as keys.
5fill in blank
hard

Fill all three blanks to loop through the array and print each key and value.

PHP
<?php
$info = array("language" => "PHP", "year" => 1995);
foreach([1] as [2] => [3]) {
    echo "$key: $value\n";
}
?>
Drag options to blanks, or click blank then click option'
A$info
B$key
C$value
D$array
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in foreach.
Omitting the => in foreach.