pandu Posted June 24, 2009 Share Posted June 24, 2009 Hello, I am having a hard time understanding the syntax used to iterate thru an array of objects using the while..do loop. For example, in the code below, what is $row? Also, if there is documentation on this online would appreciate if you could point it to me. (Did not find anything on php.net) public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_arry; } TIA Link to comment https://forums.phpfreaks.com/topic/163518-question-about-using-whiledo-to-iterate-object-arrays/ Share on other sites More sharing options...
adam84 Posted June 24, 2009 Share Posted June 24, 2009 public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); while ($row = mysql_fetch_array($result_set) ) { $object_arry[] = $row['row1']; } return $object_arry; } Link to comment https://forums.phpfreaks.com/topic/163518-question-about-using-whiledo-to-iterate-object-arrays/#findComment-862761 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 What you're seeing is a bit of a short form. Think of it like this: $row=mysql_fetch_array($result_set); while($row!==false) { $object_arry[]=$row['row1']; $row=mysql_fetch_array($result_set); } return $object_arry; because while ($row = mysql_fetch_array($result_set) ) { is really parsed as while (($row = mysql_fetch_array($result_set))!==false) { Link to comment https://forums.phpfreaks.com/topic/163518-question-about-using-whiledo-to-iterate-object-arrays/#findComment-862769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.