[snip] $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 [/snip] That is kind of an ambiguos question there Rich. What needs to be more elegant, the method? the output? You could use a foreach key/value pairing if your values are such. See http://www.php.net/manual/en/control-structures.foreach.php HTH! Jay If you must choose between two evils, pick the one you’ve never tried before! *********************************************************** * Texas PHP Developers Conf Spring 2003 * * T Bar M Resort & Conference Center * * New Braunfels, Texas * * San Antonio Area PHP Developers Group * * Interested? Contact [EMAIL PROTECTED] * *********************************************************** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php