0
0
PHPprogramming~10 mins

What is PHP - Interactive Quiz & Practice

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'
A"Hello, World!"
BHello, World!
C'Hello World'
DHello World
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text causes errors.
Using unquoted text is treated as a constant, causing errors.
2fill in blank
medium

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

PHP
<?php
[1] = "Alice";
?>
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 $ sign before variable names.
Using JavaScript style variable declarations like var or let.
3fill in blank
hard

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

PHP
<?php
$greeting = "Hello" [1] " World!";
echo $greeting;
?>
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 logical operators like & or && by mistake.
4fill in blank
hard

Fill both blanks to create an associative array with keys "name" and "age".

PHP
<?php
$person = array([1] => "Bob", [2] => 30);
?>
Drag options to blanks, or click blank then click option'
A"name"
B"age"
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys which are treated as constants.
Mixing keys with and without quotes.
5fill in blank
hard

Fill all three blanks to write a PHP function named greet that takes a $name and returns a greeting string.

PHP
<?php
function [1]([2]) {
    return "Hello, " . [3] . "!";
}
?>
Drag options to blanks, or click blank then click option'
Agreet
B$name
Dhello
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without $ inside the function.
Naming the function with a $ sign.
Using different names for parameter and inside variable.