在PHP中使用foreach循环的最后3个值 [英] Last 3 values using foreach loop in php
本文介绍了在PHP中使用foreach循环的最后3个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ $ $ $ $ $ $ $ $ $ foreach($ arr as $ key => $ value){
//打印最后3个值。
解决方案
试试这个:
$ i = 0;
foreach($ arr as $ key => $ value){
if(count($ arr) - $ i <4)
print($ value);
$ i ++;
}
I have a foreach loop. There has uncountable value. I want to print last 3 values.
foreach($arr as $key=>$value) {
//print last 3 value.
}
解决方案
Try this:
$i = 0;
foreach($arr as $key=>$value) {
if (count($arr) - $i < 4)
print($value);
$i++;
}
这篇关于在PHP中使用foreach循环的最后3个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文