我有这个数组:
$products = Array (
[0] => Array (
[keyseries_id] => 7
[product_id] => 1
[name] => Defender standaard sleutel
[price] => 6.25
[description] => Dit is een test voor de product descriptions
[image_id] => 1
[imageinfo] => Array (
[filename] => Array (
[0] => defender_thumb.jpg
[1] => defender_standaard.jpg )
[imagedescription] => Array (
[0] => dit is een testafbeelding
[1] => Dit is een 2e testafbeelding )
)
)
[1] => Array (
[keyseries_id] => 7
[product_id] => 2
[name] => Defender Klapsleutel
[price] => 7.00
[description] => Dit is de defender klapsleutel.. NU IN DE AANBIEDING!!!
[image_id] => 3
[imageinfo] => Array (
[filename] => Array (
[0] => defender_thumb.jpg
[1] => defender_klap.jpg )
[imagedescription] => Array (
[0] => Defender slot
[1] => Defender klapsleutel )
)
)
)
我想foreach
为每个filename
and做一个循环imagedescription
,所以我可以在我的应用程序中使用filename
andimagedescription
作为<img>
html 标记。有人可以告诉我怎么做吗?
++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
答案:感谢菲利普
像这样实现 foreach 循环:
<?php foreach($product['imageinfo']['filename'] as $index => $filename): ?>
<?php echo '<img src="http://localhost/sleutelservice/uploads/images/' . $filename . '" alt="' . $product['imageinfo']['imagedescription'][$index]. '">'; ?>
<?php endforeach; ?>