请考虑以下数组。php check array索引超出范围
$a['a'] = 1;
$a['b'] = 2;
$a['c'] = 3;
$a['d'] = 4;
,然后我很循环数组
foreach($a as $q => $x)
{
# Some operations ....
if(isLastElement == false ){
#Want to do some more operation
}
}
我怎么能知道当前位置last
与否?
谢谢。
作为你的阵列是不是数字索引的数组,你可以使用一个整数,它递增,并与您的阵列 – MatRt 2013-03-12 05:27:10
参见[这个答案]的'count'(HTTP://计算器.com/questions/1070244/how-to-determine-the-first-and-last-iteration-in-a-foreach-loop#1070256),它建议使用计数器来识别循环集合中的最后一个元素。 – 2013-03-12 05:28:00
@ user1073122在我的特定要求中不可能。 – Red 2013-03-12 05:31:10