note 64436 added to function.sort

From: Date: Fri, 14 Apr 2006 11:14:34 +0000
Subject: note 64436 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-108049@lists.php.net to get a copy of this message
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! :) ---- Server IP: 85.116.0.130 Probable Submitter: 213.152.61.1 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- http://master.php.net/note/edit/64436 Del: integrated -- http://master.php.net/note/delete/64436/integrated Del: useless -- http://master.php.net/note/delete/64436/useless Del: bad code -- http://master.php.net/note/delete/64436/bad+code Del: spam -- http://master.php.net/note/delete/64436/spam Del: non-english -- http://master.php.net/note/delete/64436/non-english Del: in docs -- http://master.php.net/note/delete/64436/in+docs Del: other reasons-- http://master.php.net/note/delete/64436 Reject -- http://master.php.net/note/reject/64436 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108049) next »