freelance84 Posted August 9, 2010 Share Posted August 9, 2010 I have a for loop which extracts info from a MySQL table, chooses something then needs to push each bit into an array: for($i = 0 ; $i < $query_report_rows ; ++$i) { $row= mysql_fetch_row($query_names); if($row[6] == 0) { $sName = $row[1]; } elseif($row[6] == 1) { $sName = $row[2]; } $name = "$row[0], $sName"; $print = nl2br($row[7]); } What i need is a multidimensional array to hold $name and $print: $name_print = array( array('name'=>$name 'print'=>$print ) ) How do i array push into such an array from the above for loop? (multi-dimensional array are a very weak point at the moment, so any pointers here would be very much appreciated) Link to comment https://forums.phpfreaks.com/topic/210221-array-push-multi-dimensional-array/ Share on other sites More sharing options...
xangelo Posted August 9, 2010 Share Posted August 9, 2010 <?php $name_print= array(); for($i = 0 ; $i < $query_report_rows ; ++$i) { $row= mysql_fetch_row($query_names); if($row[6] == 0) { $sName = $row[1]; } elseif($row[6] == 1) { $sName = $row[2]; } $name = "$row[0], $sName"; $print = nl2br($row[7]); $name_print[] = array('name'=>$name,'print'=>$print); } Link to comment https://forums.phpfreaks.com/topic/210221-array-push-multi-dimensional-array/#findComment-1097026 Share on other sites More sharing options...
freelance84 Posted August 9, 2010 Author Share Posted August 9, 2010 Brilliant thaks a lot (i didn't realise you could push an array into an array like that, makes perfect sense actually!) Link to comment https://forums.phpfreaks.com/topic/210221-array-push-multi-dimensional-array/#findComment-1097027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.