Welcome Guest, Not a member yet? Register   Sign In
get current array position pointer while doing foreach $object->result_array()
#1

[eluser]jayapalchandran[/eluser]
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(;Wink 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.
#2

[eluser]mddd[/eluser]
Code:
$list = $object->result_array();
$length = sizeof($list);
foreach($list as $key=>$value)
{
  if ($key==$length-1) echo 'This is the last item';
  if ($key==$length-2) echo 'This is the item before the last item';
}
#3

[eluser]jayapalchandran[/eluser]
Excellent.
Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB