codeigniter - 在执行foreach时获取当前数组位置$ object-> result_array() [英] codeigniter - get current array position while doing foreach $object->result_array()
本文介绍了codeigniter - 在执行foreach时获取当前数组位置$ object-> result_array()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在执行foreach时获取当前数组位置指针$ object-> result_array()
get current array position pointer while doing foreach $object->result_array()
您好,
考虑这个情况。
Hi, consider this, a case.
foreach($object->result_array() as $rs)
{
//how do i display the current array element index that is the iteration index.
//i want to call a function when the iterator is in the last-1 position.
// and more specifically i want to use it in this place and not any other for(;;) loops.
// and even it is an example with other loops then that is fine.
}
应该有一个选项或使用current
我试过,但仍然需要做一些分析...
而不是调试和跟踪数组元素我发布此线程。
There should be an option or by using current() function. I had tried but still i have to do some analysis… Instead of debugging and tracing the array elements i am posting this thread.
最重要的是可以使用for循环吗?
推荐答案
添加 => $ key
这样也可以获取密钥:
Add => $key
like this to get key as well:
foreach($object->result_array() as $rs => $key)
{
echo $key;
}
with a for循环?
and above all is it possible to do it with a for loop?
是这样:
for($i = 0; $i < count($object->result_array()); $i++)
{
// your code...
}
这篇关于codeigniter - 在执行foreach时获取当前数组位置$ object-> result_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文