可能重复:
为什么我的 PHP 多维数组不起作用?
更新
我希望能够添加 URL category.php?filter=Blue and green
,或者category.php?filter=Red
然后让我的数组列表仅显示具有这些值的颜色 - 否则它将列出所有数组。
<?php
$array = array(
"1" => array("red", "black", "blue and green"),
"2" => array("orange"),
"3" => array("silver", "gold"),
"4" => array("pruple"),
"5" => array("pink", "yellow"),
"6" => array("black")
);
# no more more edits, loop begins below
# limit the the rows by 3 and break
$data = array_chunk($array, 3);
/*#######################################
No more edits DO NOT EDIT FURTHER
#######################################*/?>
<?php
foreach ($array as $data):
?>
<div class="item" id="item_<?= $row ?>">
<div class="itemdata">
<?php #foreach ($array as $row): ?>
<?php foreach ($data as $row): ?>
<?php if (in_array($row, explode(' and ', $_GET['filter']))): ?>
Product Link = <?=$row?>
<?php endif; ?>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>
我已经根据下面的帖子更新了我的代码。到目前为止,它只循环了两个项目 - 没有filter
应用于 URL