Re: assignment of data into a 2 dimensional array
| From: | Torsten Roehr | Date: | Mon, 03 May 2004 19:33:55 +0000 |
| Subject: | Re: assignment of data into a 2 dimensional array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185238@lists.php.net to get a copy of this message | ||
"Adam Williams" <awilliam@mdah.state.ms.us> wrote in message
news:Pine.LNX.4.44.0405031415490.790-100000@roark.mdah.state.ms.us...
> 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.
Output the array this way:
foreach ($array as $key => $value) {
echo 'date: ' . $key . ', count: ' . count(array_unique($value));
}
>
> 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.
Does this mean you would like to recognize EVERY day in the specified time
range even if they are not part of the array?
Regards, Torsten
>
> 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.