Hi, I've seen in the code I'm working on, the following:
foreach( $mysql_result as $row ) $site_id = $row->id;
$mysql_result is, of course a mysql_result, so this foreach is equivalent to a while( mysql_fetch_row() )
Sometimes, the result is known to yield only one row, but the code still has a "foreach" so it gives the impression of being a loop through many rows.
I tried using each() but doesn't work for this.
I know I could use mysql_fetch_row(), but the code should be DB independent so I can't use DB specific functions. Is there something like each() that works in this case just as the first iteration of foreach() ?
PS: what I do currently for readability is turn the previous example to this:
foreach( $mysql_result as $row ) break;
$site_id = $row->id;
So it's pretty obvious that the foreach will at most loop only once.