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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.