Doug_M Posted May 7, 2009 Share Posted May 7, 2009 Hi, I'm trying to create a multi-dimensional array from the results of an MDB2 query. All the examples I can find have the array "hard-coded" so to speak and so are not helpful. Here's what I have: // perform query $result = $mdb2->query($sql); // get results if ($result != null) { // build app array while ($row = $result->fetchRow()) { $apps[] = array(array($row[0], $row[1], $row[2])); } } Of course this doesn't work. The brackets on $apps work for a single-dimension array. I've tried two sets of brackets but that's not right either. Regards, Doug Link to comment https://forums.phpfreaks.com/topic/157255-solved-creating-multi-dimensional-arrays-in-a-loop/ Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 // perform query $result = $mdb2->query($sql); $apps = array(); // get results if ($result != null) { // build app array while ($row = $result->fetchRow()) { $apps[] = $row; } print_r($apps); } Should produce a multi-dimensional array. Link to comment https://forums.phpfreaks.com/topic/157255-solved-creating-multi-dimensional-arrays-in-a-loop/#findComment-828672 Share on other sites More sharing options...
Doug_M Posted May 7, 2009 Author Share Posted May 7, 2009 Sweet! Short and simple (and obvious too). Thanks, Doug Link to comment https://forums.phpfreaks.com/topic/157255-solved-creating-multi-dimensional-arrays-in-a-loop/#findComment-828675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.