Reputation: 2985
I am returning an array of values using mysql_fetch_array.
In the while loop, i need to perform an if condition on the next element of the array.
E.g
if next($row) == 'test'
{
...
}
The thing is 'next($row)' is returning me the index of the next element in the array. I would like to test for the next $row("name").
if next($row("name")) == 'test'
{
...
} //this code is incorrect
Is there a way of doing this in php?
Thanks a lot for your help :)
Upvotes: 1
Views: 1473
Reputation: 3282
foreach ($rows as $k => $row) {
if (isset($rows[$k+1]) && $rows[$k+1] == 'test') //do something
// Do normal stuff here
}
Upvotes: 1
Reputation: 725
if the "next($row)" gives you the index of the next cell in the array then just use it to perform the test. $arr[next($row)] = the next cell value/obj/whatever you have there
Upvotes: 2