OK this is a hard one:
Problem: I read from a csv file, put fields of the line in an array, and again add this to an two-dimensional array.
Then I compare the first entries of all the arrays (date) and sort them.
Solved problem usually...
But here we go.
After sorting it, an empty array is inserted... and where? guess what: in between the two arrays with the date of today and tomorrow...
is this a bug.....
any answers appreciated... I´m about to explode!!!!! aarrrglllll....
FAB
Code follows:
<?php
$filename1=".xyz";
$fp3=fopen($filename1,"r");
$lines=0;
while($dump=@fgetcsv($fp3,filesize($filename1), "|")){
$lines++;
};
rewind($fp3);
$q=0;
for($s=0; $s<$lines; $s++){
$array[$q]=fgetcsv($fp3,filesize($filename1),"|");
$q++;
};
for($l=0;$l<$lines;$l++){
print "Unsorted:" .$array[$l][0]. "<BR>";
}
for($i=0;$i<$q;$i++){
if($array[$i][0]=="" || $array[$i][0]=="\n" || $array[$i][0]=="\r"){break;}
else {
$t=$i+1;
$date1=strtotime($array[$i][0]);
$date2=strtotime($array[$t][0]);
if($date1 > $date2) {
$help=$array[$i];
$array[$i]=$array[$t];
$array[$t]=$help;
$i=-1;
};
};
};
for($z=0;$z<=$lines;$z++){
print "Sortedt: " . $array[$z][0] . "<BR>";
}
?>
Here´s the output on the webpage:
Unsorted:2000-09-14
Unsorted:2000-09-09
Unsorted:2000-09-16
Unsorted:2000-09-24
Unsorted:2000-09-15
Sorted: 2000-09-09
Sorted: 2000-09-14
Sorted:
Sorted: 2000-09-15
Sorted: 2000-09-16
Sorted: 2000-09-24