我有一个这样的多维数组:
Array
(
[Category1] => Array
(
[1] => Array
(
[0] => Img 1
[1] => Title 1
[2] => Text 1
)
[5] => Array
(
[0] => Img 17
[1] => Title 17
[2] => Text 5
)
[10] => Array
(
[0] => Img 1
[1] => Title 6
[2] => Text 10
)
[16] => Array
(
[0] => Img 16
[1] => Title 12
[2] => Text 16
)
)
[Category2] => Array
(
[2] => Array
(
[0] => Img 2
[1] => Title 2
[2] => Text 2
)
[6] => Array
(
[0] => Img 18
[1] => Title 18
[2] => Text 6
)
[13] => Array
(
[0] => Img 13
[1] => Title 9
[2] => Text 13
)
)
[Category3] => Array
(
[3] => Array
(
[0] => Img 3
[1] => Title 3
[2] => Text 3
)
[7] => Array
(
[0] => Img 19
[1] => Title 19
[2] => Text 7
)
[11] => Array
(
[0] => Img 11
[1] => Title 7
[2] => Text 11
)
[14] => Array
(
[0] => Img 14
[1] => Title 10
[2] => Text 14
)
)
[Category4] => Array
(
[4] => Array
(
[0] => Img 4
[1] => Title 4
[2] => Text 4
)
[8] => Array
(
[0] => Img 20
[1] => Title 20
[2] => Text 8
)
[15] => Array
(
[0] => Img 15
[1] => Title 11
[2] => Text 15
)
)
[Category5] => Array
(
[9] => Array
(
[0] => Img 9
[1] => Title 5
[2] => Text 9
)
)
[Category6] => Array
(
[12] => Array
(
[0] => Img 12
[1] => Title 8
[2] => Text 12
)
)
)
我需要帮助才能这样查看,$myarray如顶部示例所示。在 firs foreach 中,一切都没关系,但在 sencond 和第三个 foreach 中,如果我在一个类别中有多个数组,它会被配音并且不直接显示。
<div id="tab-container">
<ul>
<?php foreach ($myarray as $category => $detail) { ?>
<li><a href="#tab-<?=$category?>"><?=$category?></a></li>
<?php }; ?>
</ul>
<div>
<?php foreach (??? ??? ???) { ?>
<div id="tab-<?=$category?> for ex Category 1 contain Array (1, 5 10, 16)">
<div class="tab-content_left">
<div><img src="<?=base_url();?>img/$value[0] for ex Img 1" /></div>
<div>$value[1] for ex Title 1</div>
<div>$value[2] for ex Text 1</div>
</div>
<div class="tab-content_right">
<?php foreach (??? ??? ???) { ?>
<div><img src="<?=base_url();?>img/"$value[0] for ex Img 17 /></div>
<div>$value[1] for ex. Title 17</div>
<div>$value[2] for ex Text 5</div>
<?php }; ?>
</div>
</div>
<?php }; ?>
</div>
</div>
感谢。请问一些想法,我怎样才能把每个 cicles 放在哪里?
First foreach:
<?php foreach ($mainArray as $categoryKey => $singleCategory) { ?>
第二名:
<?php foreach ($singleCategory as $categoryEntry) { ?>
注意:
要获取类别名称,请在第一个 foreach 中写入$categoryKey
。要获取数据写入:$singleCategory['image']
在第二个foreach内。
检查每个文档。