array_slice但用于图像php [英] array_slice but for images php
本文介绍了array_slice但用于图像php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了这段代码
<?php
$a = Meme::all();
$b = count($a);
for($i=$b;$i<$b-3;$i--) {
?> <div class="col-sm-6"><img class="lazy" data-src="<?php echo $a[$i]->path; ?>" /> </div>
<?php
}?>
我想输出最后3个模因(图像),但是此for循环不起作用。所以我找到了一个叫做array_slice的东西,我想使用它,但是每个人都在使用print_r,但是在这种情况下,我不需要它。有什么建议吗?
i want to output the last 3 memes(images) but this for loop doesn't work. So i found something that is called array_slice and i wanted to use it but everyone was using print_r but in this case i don't need it. So any suggestions?
推荐答案
将数组 $ a
的这3个元素存储在新数组中 $ b
通过使用 array_slice
:
Store those 3 elements of array $a
in a new array $b
by using array_slice
:
<?php
$a = Meme::all();
$b = array_slice($a, 3);
for ($i = 0; $i < 3; $i++){
?>
<div class="col-sm-6"><img class="lazy" data-src="<?php echo $b[$i]->path; ?>" /> </div>
<?php
}
?>
这篇关于array_slice但用于图像php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文