Re: assignment of data into a 2 dimensional array
| From: | Torsten Roehr | Date: | Mon, 03 May 2004 19:04:09 +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-185232@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.0405031332560.790-100000@roark.mdah.state.ms.us...
> On Mon, 3 May 2004, John W. Holmes wrote:
>
> > Can you give an example of where this data is coming from and how its
> > formatted before you want to reformat it? Is the list and date the
result of
> > a query or do you have the list in a separate variable or array?
> >
> > $list1 = '2,3,4,5';
> > $list2 = '6,3,5,6,7';
> >
> > How do those relate to the dates? Are you running multiple queries? A
short
> > code example would help us a lot here.
> >
> > ---John Holmes...
> >
> >
>
> the final array should look like:
>
> array[x][x]:
>
> 04-20-2004 -> 2379
> 2380
> 296
> 314
> 2396
> 2395
>
> 04-21-2004 -> 2398
> 1403
> 1736
> 1828
> 1203
What about this:
$array = array();
// start loop with $date and $cardno
// check if a key with this date already exists, if not add it as an empty
array
if (!isset($array[$date]) $array[$date] = array();
// add card no. to date array
$array[$date][] = $cardno;
// end loop
Then you could loop through the array again and apply array_unique() to each
date array to remove duplicate values (which you didn't want).
What do you think?
Regards, Torsten