Jump to content

array push multi-dimensional array


freelance84

Recommended Posts

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

<?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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.