foreach($array as $i=>$values) { echo $values['id'],$values['name'] }
On Mon, 19 Aug 2002, Richard Fox wrote: > Hi, > > Given the array $array initialized by: > > $query = "SELECT id,name FROM MYTABLE"; > $result = mysql_query($query); > $nrows = mysql_num_rows($result); > for ($i=0; $i<$nrows; $i++) { > $arr = mysql_fetch_array($result); > $array[$i]['id'] = $arr['id']; > $array[$i]['name'] = $arr['name']; > } > > I know I can have a similar 'for' loop to step through the array, from 0 to >count($array) > But I would like to do something more elegant, with a foreach loop. But I have been >unsuccessful as a foreach seems appropriate only with a single dimensional array. Can >someone suggest a more elegant solution? Thanks, Rich > P.S. yes, I am fairly new to PHP, less than 6 months. Probably my array loading >method could be improved also! > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php