开发者

codeigniter - get current array position while doing foreach $object->result_array()

开发者 https://www.devze.com 2023-01-09 23:14 出处:网络
get current array position pointer while doing foreach $object->result_array() Hi, consider this, a case.

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.
}

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.

and above all is it possible to do it with a for loop?


Add => $key like this to get key as well:

foreach($object->result_array() as $rs => $key)
{
   echo $key;
}

and above all is it possible to do it with a for loop?

Yes like this:

for($i = 0; $i < count($object->result_array()); $i++)
{
  // your code...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号