Challenge - 5 Problems
PHP $_GET Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP code using $_GET?
Consider the URL:
http://example.com/page.php?name=Alice&age=30. What will this PHP code output?PHP
<?php $name = $_GET['name']; $age = $_GET['age']; echo "Name: $name, Age: $age"; ?>
Attempts:
2 left
💡 Hint
Check how $_GET accesses URL parameters by their keys.
✗ Incorrect
The $_GET superglobal array contains URL parameters as key-value pairs. Accessing $_GET['name'] returns 'Alice' and $_GET['age'] returns '30'.
🧠 Conceptual
intermediate2:00remaining
What happens if a URL parameter is missing in $_GET?
Given the URL
http://example.com/page.php?user=Bob, what will be the output of this code?PHP
<?php $user = $_GET['user']; $age = $_GET['age']; echo "User: $user, Age: $age"; ?>
Attempts:
2 left
💡 Hint
Accessing a missing key in $_GET causes a notice error.
✗ Incorrect
Trying to access $_GET['age'] when 'age' is not in the URL causes a PHP Notice: Undefined index error.
🔧 Debug
advanced2:00remaining
Why does this PHP code not output the expected $_GET value?
URL:
http://example.com/page.php?city=Paris
Code:
<?php $city = $_GET[city]; echo "City: $city"; ?>What is the problem?
Attempts:
2 left
💡 Hint
Array keys must be quoted strings in PHP.
✗ Incorrect
In PHP, array keys must be quoted strings. Using $_GET[city] without quotes causes PHP to look for a constant named city, which is undefined and triggers a notice.
❓ Predict Output
advanced2:00remaining
What is the output of this PHP code with multiple $_GET parameters?
URL:
http://example.com/page.php?item=book&price=15&discount=5
Code:
<?php $item = $_GET['item']; $price = $_GET['price']; $discount = $_GET['discount']; $total = $price - $discount; echo "Item: $item, Total Price: $total"; ?>
Attempts:
2 left
💡 Hint
URL parameters are strings; PHP converts them to numbers in arithmetic.
✗ Incorrect
PHP converts string numbers to integers automatically in arithmetic operations. 15 - 5 equals 10.
📝 Syntax
expert2:00remaining
Which option causes a syntax error when accessing $_GET parameters?
Identify the code snippet that will cause a PHP syntax error.
Attempts:
2 left
💡 Hint
Check for missing semicolons in PHP statements.
✗ Incorrect
Option A is missing the semicolon at the end of the statement, causing a syntax error.