我有一个像这样的数组
Array ( [0] => Array ( [keyword] => nothing [id] => 44 ) [1] => Array ( [keyword] => everything [id] => 45 ) [2] => Array ( [keyword] => dogs [id] => 46 ) )
我基本上想要创建一个这样的链接:
<a href="mypage.php?pid=ID">KEYWORD</a>
所以我在考虑使用array_walk,但是我不认为这会在多维数组上工作,我如何让它遍历我的数组并为数组中的每个条目输出ID和关键字?
答案 0 :(得分:1)
使用foreach
循环:
$array = array(
array(
"keyword" => "anything",
"id" => 44
),
array(
"keyword" => "everything",
"id" => 45
),
array(
"keyword" => "dogs",
"id" => 46
),
);
foreach ($array as $link) {
$keyword = $link["keyword"];
$id = $link["id"];
echo "<a href='mypage.php?pid=$id'>$keyword</a>" . PHP_EOL;
}