array_unique tests the values of each element of the top level array - which
are all 'array' - hence you only get one element left

the way I'd do this is ...
$archive_nav["$year/$month"] = array(month => $month, year => $year,
longmonth => $longmonth);

this will prevent duplicate combinations of month and year (and,
incidentally, allow you to sort on year and month very easily).

Tim Ward

> -----Original Message-----
> From: sasha [mailto:[EMAIL PROTECTED]]
> Sent: 19 August 2002 19:10
> Subject: array_unique & multi-dimensional arrays
> I am trying to clean up some junky code in a journal/news type 
> script and redoing the archive navigation.  I am pulling all of 
> the dates of the entries and pushing it into a multi-
> dimensional array like so:
> array_push($archive_nav, array(month => $month, year => $year, 
> longmonth => $longmonth));
> I assumed I could just use array_unique to filter out all of 
> the duplicates in the array.  But it doesn't seem to work that 
> way, and the only month/year combo I end up with is the very 
> oldest one (according to year/month) in the array.
> $archive_nav = array_unique($archive_nav);
> If I leave out array_unique, I am getting all of the 
> appropriate month/year combos in my script while doing a 
> foreach... just one for every single entry in the database for 
> that combo (which is a lot in some cases!).
> Is there a better way to do this?
> sasha

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to