我在一篇文章中添加了许多缩略图,这是 Zend 框架的新内容,所以我不确定打印这个数组的编码风格。
我在 MongoDB 中的数组如下所示:
"thmbs": [
{
"src": "examp.com/img/product1.jpg",
"caption": "Top View"
},
{
"src": "examp.com/img/product2.jpg",
"caption": "Side View"
},
]
首先,我想检查数组以查看它是否包含任何内容,然后打印替代文本的图像和标题。这是正确的方向吗?
<?php if ($this->thmbs) {
foreach($this->thmbs->src as $val){?>
<img id="lead-image" src="<?= $this->thmbs->src ?>" alt="<?= $this->thmbs->caption?>"/>
<?php }} ?>