-1

Goal: I am trying to print all the super global variables one by one by fetching it from a list of array I created.

$sectionsToPrint = array(
  'server' => '$_SERVER','get'=>'$_GET','post'=>'$_POST'
);


foreach ($sectionsToPrint as $k => $v) {
        foreach ($$v as $k2 => $v2) { //#LineNumber
          echo "$k2=$v2<br /><br />";
        }
    }
AlamSirji
  • 1
  • 4

1 Answers1

0

Instead of quoting superglobals in an array, use them plainly:

$sectionsToPrint = [
    'server' => $_SERVER, 'get' => $_GET, 'post' => $_POST
];


foreach ($sectionsToPrint as $k => $v) {
    foreach ($v as $k2 => $v2) {
        echo "$k2=$v2<br /><br />";
    }
}

or (as suggested in the comments):

$sectionsToPrint = array_merge($_SERVER, $_GET, $_POST);

foreach ($sectionsToPrint as $k => $v) {
    echo "$k=$v<br /><br />";
}
N'Bayramberdiyev
  • 5,636
  • 7
  • 23
  • 43