Re: Distinct Items in an Array
| From: | Christopher J. Crane | Date: | Thu, 17 Apr 2003 15:02:38 +0000 |
| Subject: | Re: Distinct Items in an Array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144296@lists.php.net to get a copy of this message | ||
I am going to try this and see what happens. Thank you for your efforts. I
will let you know the outcome. Thank again.
"Peter Pistorius" <peterp@podbox.co.za> wrote in message
news:20030417143507.65058.qmail@pb1.pair.com...
> 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
>
>