Re: Distinct Items in an Array

From: Date: Thu, 17 Apr 2003 15:24:36 +0000
Subject: Re: Distinct Items in an Array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-144299@lists.php.net to get a copy of this message
Ok Here is he issue, the file is a CSV type file and contains a number of "columns" Here is a sample Date,Open,High,Low,Close,Volume 16-Apr-03,7.99,8.33,7.97,8,709900 15-Apr-03,7.62,7.95,7.62,7.95,971300 14-Apr-03,7.4,7.85,7.35,7.75,434700 31-Mar-03,7.24,7.37,7.1,7.1,440600 28-Mar-03,7.34,7.42,7.28,7.3,302000 27-Mar-03,7.41,7.49,7.24,7.33,356400 26-Mar-03,7.55,7.55,7.15,7.41,394300 25-Mar-03,7.2,7.6,7.11,7.6,292800 I am not sure how to mold your script around a multiple column file "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 > >

« previous php.general (#144299) next »