I am returning an array of values using mysql_fetch_array.
我使用mysql_fetch_array返回一个值数组。
In the while loop, i need to perform an if condition on the next element of the array.
在while循环中,我需要对数组的下一个元素执行if条件。
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").
事情是'next($ row)'返回数组中下一个元素的索引。我想测试下一个$行(“名称”)。
if next($row("name")) == 'test'
{
...
} //this code is incorrect
Is there a way of doing this in php?
有没有办法在PHP中这样做?
Thanks a lot for your help :)
非常感谢你的帮助 :)
2 个解决方案
#1
2
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
如果“next($ row)”为您提供数组中下一个单元格的索引,则只需使用它来执行测试。 $ arr [next($ row)] =下一个单元格值/ obj /无论你有什么
#2
1
foreach ($rows as $k => $row) {
if (isset($rows[$k+1]) && $rows[$k+1] == 'test') //do something
// Do normal stuff here
}
#1
2
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
如果“next($ row)”为您提供数组中下一个单元格的索引,则只需使用它来执行测试。 $ arr [next($ row)] =下一个单元格值/ obj /无论你有什么
#2
1
foreach ($rows as $k => $row) {
if (isset($rows[$k+1]) && $rows[$k+1] == 'test') //do something
// Do normal stuff here
}