Re: assignment of data into a 2 dimensional array

From: Date: Mon, 03 May 2004 19:23:27 +0000
Subject: Re: assignment of data into a 2 dimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185235@lists.php.net to get a copy of this message
On Mon, 3 May 2004, John W. Holmes wrote: > while($row = mssql_fetch_array($result)) > { > $array[$row['date']][] = $row['cardnum']; > } > > ?? > > That should produce something like > > Array ( '04-20-2004' => array(2379,2380,296,314,2396,2395), '04-21-2004' > => > array(2398,1403,1736,1828,1203)) > > count($array['04-21-2004']) will tell you how many "cardnum"s are assigned > to that date. > > foreach($array['04-21-2004'] as $cardnum) > { echo $cardnum; } > > will allow you to loop through each date and print the cardnums associated > with it... > > Post back if that's not what you're after. > > ---John Holmes... > > Yeah, you are on the right track, 2 things though: 1) I need to remode duplicate cardnum entries from the 2nd dimension. Another person mentioned array_unique() but looking at php.net/array_unique i don't see how make it operate on only the 2nd dimension. 2) Since the person can enter a range of dates, as an example 4-20-2004 through 05-03-2004 in the html form, how can I print the date and the corresponding cardnum's after I've removed the unique patron numbers? It would need to go onto the next day after loop or printing second dimension get to a a dimension that is not set. I was thinking of a foreach inside of a while loop, but I just don't know enough about arrays to figure out the code.

« previous php.general (#185235) next »