阅读 GET 数据

来自 GET 请求的数据以关联数组的形式存储在超全局 $_GET 中。

请注意,访问不存在的数组项会生成通知,因此应始终使用 isset()empty() 函数或 null coalesce 运算符检查是否存在。

示例:(对于 URL /topics.php?author=alice&topic=php

$author = isset($_GET["author"]) ? $_GET["author"] : "NO AUTHOR";
$topic = isset($_GET["topic"]) ? $_GET["topic"] : "NO TOPIC";

echo "Showing posts from $author about $topic";

Version >= 7

$author = $_GET["author"] ?? "NO AUTHOR";
$topic = $_GET["topic"] ?? "NO TOPIC";

echo "Showing posts from $author about $topic";