I am learning a GET method in php, and want to display GET method in multidimentional array using foreach loop.

This is for a backend web, running PHP 7, MySQL 10 and Apache 2. In the past, I have tried it in XAMPP but always got different answer.

<?php


$game = [[  "Nama_Game"=>"Grand Theft Auto V",
            "Release_Date"=>2013],
        [   "Nama_Game"=>"Payday The Heist",
            "Release_Date"=>2011]];









<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Game</title>
</head>
<body>
<h1>Learn Get Method</h1>

<!--- $_GET-->
<!-- <?php //foreach($game as $nv) : ?>
<ul>
<li>
<a href="variabel-global2.php">
<?php //print_r($nv["Nama_Game"]); ?>
</a>
</li>
<li><?php //print_r($nv["Release_Date"]); ?></li> -->

</ul>
<?php //endforeach; ?>

<ul>
<?php foreach($game as $vx) : ?>
    <li>
    <a href="variabel-global2.php?Nama_Game"<?= $vx["Nama_Game"]; ?> ><?= $vx["Nama_Game"]; ?></a>
    </li>
<?php endforeach; ?>
</ul>


</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Detail Game</title>
</head>
<body>
    <ul>
        <li><?= implode($_GET=["Nama_game"]);?></li>
        <li><?= implode($_GET=["Release_Date"]);?></li>
    </ul>

<a href="variabel-global.php">Kembali ke halaman awal</a>

</body>
</html>

I expect the output of Grand Theft Auto V is Grand Theft Auto V and 2013 but the actual output is Nama_Game and Release_Date.

1 Answers

0
Community On
Hello test,

    $game = [
        [
            "Nama_Game" => "Grand Theft Auto V",
            "Release_Date" => 2013,
        ],
    ];

    <?php foreach($game as $item) : ?>
        $query = http_build_query([
            'Nama_Game' => $item["Nama_Game"],
            'Release_Date' => $item["Release_Date"],
        ]);
        <li>
            <a href="variabel-global2.php>"<?= $query; ?> ><?=$item["Nama_Game"]; ?></a>
        </li>
    <?php endforeach; ?>

Recup a result 

    $_GET['Nama_Game'] `OR` $_GET['Release_Date']