我正在学习php中的GET方法,并想使用foreach循环在多维数组中显示GET方法。
这是用于运行PHP 7,MySQL 10和Apache 2的后端Web的。过去,我曾在XAMPP中尝试过它,但总是得到不同的答案。
<?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>
我希望侠盗猎车手V的输出是侠盗猎车手V和2013,但实际输出是Nama_Game和Release_Date。
答案 0 :(得分:0)
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']