【发布时间】:2015-08-03 19:03:15
【问题描述】:
<?php $j=0;
while ($j<2){ if(empty($recent['id'][$k])) break;?>
<div class="col-md-5 col-xs-7" style="padding:0px;">
<div class="img-sm">
<?php if(!empty($recent['image'][$k])) { ?>
<img class="img-responsive" src="<?php echo base_url().url_thumb($recent['image'][$k],'konsultasi/') ?>" />
<?php } else { ?>
<img class="img-responsive" src="<?php base_url().'assets/images/logo.png' ?>" />
<?php } ?>
</div>
</div>
<?php $j++; $k++; } ?>
问题是,如果空图像对我不起作用。
【问题讨论】:
-
你能发布你的
$recent数组 -
发布
var_dump($recent)的输出。 -
我会假设正在检查的内容!empty 不是数组,不存在。尝试使用 'isset()' 和 '!= NULL' 的组合
-
这是它 array(4) { ["id"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) " 1" } ["image"]=> array(2) { [0]=> string(69) "assets/images/uploads/konsultasi/010df4f05a905f167421ecda7fd1fdd0.jpg" [1]=> string(69) "assets/images /uploads/konsultasi/da573b42cfd55cb8df80500bb866bef5.jpg" } ["title"]=> array(2) { [0]=> string(9) "test lagi" [1]=> string(18) "testing konsultasi" } [ “日期”]=> 数组(2){ [0]=> 字符串(11)“2015 年 7 月 14 日”[1]=> 字符串(11)“2015 年 7 月 13 日”} }
标签: php if-statement