How can get_defined_vars() be used to retrieve and display superglobal arrays in PHP?

To retrieve and display superglobal arrays in PHP using get_defined_vars(), you can simply call the function and then access the superglobal arrays within the returned associative array. This function returns an associative array containing all defined variables, including superglobals like $_GET, $_POST, $_SESSION, etc. You can then iterate through this array to display the values of the superglobal arrays.

$vars = get_defined_vars();

foreach ($vars as $key => $value) {
    if (is_array($value) && isset($GLOBALS[$key])) {
        echo "Superglobal array $key:<br>";
        foreach ($GLOBALS[$key] as $k => $v) {
            echo "$k: $v<br>";
        }
        echo "<br>";
    }
}