0
0
PHPprogramming~20 mins

$_GET for URL parameters in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP $_GET Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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";
?>
AName: , Age: 30
BName: Alice, Age: 30
CName: Alice, Age:
DName: , Age:
Attempts:
2 left
💡 Hint
Check how $_GET accesses URL parameters by their keys.
🧠 Conceptual
intermediate
2: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";
?>
AUser: Bob, Age: 0
BUser: Bob, Age: NULL
CUser: Bob, Age:
DUser: Bob, Age: Notice: Undefined index: age
Attempts:
2 left
💡 Hint
Accessing a missing key in $_GET causes a notice error.
🔧 Debug
advanced
2: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?
AMissing quotes around 'city' key causes a PHP notice or error.
BThe $_GET array is empty because URL parameters are not passed.
CThe variable $city is overwritten before echo.
DThe echo statement syntax is incorrect.
Attempts:
2 left
💡 Hint
Array keys must be quoted strings in PHP.
Predict Output
advanced
2: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";
?>
AItem: book, Total Price: 20
BItem: book, Total Price: 15-5
CItem: book, Total Price: 10
DItem: book, Total Price: 0
Attempts:
2 left
💡 Hint
URL parameters are strings; PHP converts them to numbers in arithmetic.
📝 Syntax
expert
2:00remaining
Which option causes a syntax error when accessing $_GET parameters?
Identify the code snippet that will cause a PHP syntax error.
A$value = $_GET['key']
B$value = $_GET[key];
C$value = $_GET["key"];
D$value = $_GET['key'];
Attempts:
2 left
💡 Hint
Check for missing semicolons in PHP statements.