note 64436 rejected from function.sort by bjori

From: Date: Fri, 14 Apr 2006 11:41:30 +0000
Subject: note 64436 rejected from function.sort by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108052@lists.php.net to get a copy of this message
Note Submitter: neil_caborn at hotmail dot com ---- how do I sort an array by date? It's for a flat file blog and it works fine BUT displays by oldest date first (as it's written to the file) and I want to show the most recent posting. Below is my code now which displays everyting as is : <?php $string = file("blog.txt"); usrot($string); foreach ($string as $key => $value) { $blogarray[$key] = explode ("||",$value); } for ($blog=0; $blog < sizeof($string); $blog++) { if($blog==0){ $working_date = $blogarray[$blog][0]; $date = $blogarray[$blog][0]."<br>"; } elseif($blogarray[$blog][0] != $working_date){ $date = $blogarray[$blog][0]."<br>"; $working_date = $blogarray[$blog][0]; } else{ $date = null; } $time = $blogarray[$blog][1]; $blogcontent = $blogarray[$blog][2]; print "<p>"; print "<b>".$date."</b>"; print $time."<br>"; print $blogcontent; print "</p>"; } ?> Please email me if you have a solution to this problem for me. Thanks! :)

« previous php.notes (#108052) next »