Re: Distinct Items in an Array
| From: | Peter Pistorius | Date: | Thu, 17 Apr 2003 14:31:01 +0000 |
| Subject: | Re: Distinct Items in an Array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144288@lists.php.net to get a copy of this message | ||
Here you go Sir:
<?php
$fp = fopen('./file.txt', 'r');
$temp_array = null;
while (!feof($fp))
{
$date = fgets($fp,4096);
$date = explode('-', $date);
$temp_array[$date[0]] += 1;
}
fclose($fp);
foreach ($temp_array AS $key=>$value) {
echo "$key -> $value <br />";
# $key is numeric value of month, $value is the amount of occurances in
the file.
$store_array[] = "$key";
for ($i = 1; $i < $value; $i++) {
array_push($store_array, null);
}
}
print_r($store_array);
?>
And the file (file.txt):
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
01-01-2003
02-01-2003
02-01-2003
02-01-2003
02-01-2003
02-01-2003
03-01-2003
04-01-2003
04-01-2003
04-01-2003
04-01-2003
04-01-2003
04-01-2003
04-01-2003
Regards,
Peter "Pod" Pistorius
(Poor, unemployed, student in South Africa)
peterp@podbox.co.za