Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 :)

share|improve this question
Duplicate question of this: stackoverflow.com/questions/396519/… – Tom Oct 25 '11 at 10:09

2 Answers

up vote 2 down vote accepted

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

share|improve this answer
foreach ($rows as $k => $row) {
    if (isset($rows[$k+1]) && $rows[$k+1] == 'test') //do something

    // Do normal stuff here
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.