【发布时间】:2012-10-01 09:48:07
【问题描述】:
更新
我希望能够添加 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
【问题讨论】:
-
这个
<div class="item" id="item_<?=$row?>">可能不会达到你的预期。