Hi,
I have a massive array containing dates. This array is unsorted and there are lots of duplicates. I need to create a report that displays this array as a kind of histogram based on number of occurences (how many of each date). For example in the array I have:
2007-06-22
2007-06-23
2007-06-23
2007-06-23
2007-06-24
2007-06-24
I want to format this information so it looks like below:
2007-06-22 1
2007-06-23 3
2007-06-24 2
The dates in the array are in no particularly order and I would also like to format the results so they are in date order. I then want to use the number of occurence data to create a line graph but need to get to this stage first. Can anyone advise the best way to do this?
Thanks
James
Formatting my array ....
Moderator: General Moderators
Re: Formatting my array ....
http://us3.php.net/manual/en/ref.array.php
Array functions would be the best way, assuming you couldn't use objects, or a normalized database to do this
Array functions would be the best way, assuming you couldn't use objects, or a normalized database to do this
Re: Formatting my array ....
Use array_unique($array) to get unique values in array.
Re: Formatting my array ....
That'll torch the counts he's looking for.adroit wrote:Use array_unique($array) to get unique values in array.
Something like this should work;
Code: Select all
foreach($whateverYourArrayIs as $date)
{
$counts[$date]++;
}
ksort($counts);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
james_withers
- Forum Newbie
- Posts: 6
- Joined: Mon Aug 04, 2008 8:03 am
Re: Formatting my array ....
Thanks (everyone) for the advice. Will check out the loop method and the array functions ...
James
James