Junior — Middle
How can you display on the screen a list of names obtained through URL query parameters using the GET method?
sobes.tech AI
Answer from AI
To output a list of names passed via URL GET parameters in PHP, you can use the superglobal array $_GET. For example, if the URL looks like:
http://example.com/page.php?names[]=Ivan&names[]=Maria&names[]=Peter
You can access the array and display the names:
<?php
if (isset($_GET['names']) && is_array($_GET['names'])) {
foreach ($_GET['names'] as $name) {
echo htmlspecialchars($name) . "<br>";
}
} else {
echo "Names not passed";
}
?>
It's important to use htmlspecialchars to prevent XSS when outputting data received from the request.