note 93464 added to function.usort

From: Date: Fri, 11 Sep 2009 06:51:45 +0000
Subject: note 93464 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-160442@lists.php.net to get a copy of this message
I want to sort a file that has a number with information in decending order by the number and file.txt looks like this: -255 | Phils bills 3437 | joes account 0 | mikes spending -10 | Sams spending 212 | Jims account The following php is how I do it and it partially works. The positive numbers list high to low, followed by the zeros, but afterwards all the negative numbers are low to high. How can I fix that part? $filenmef = temp.txt'; $handle = fopen($filenmef, 'w'); $namesfile = file.txt"; $nfopen = file($namesfile); foreach ($nfopen as $line_num => $line) { list($rank, $webname) = split (" [|] ", $line); } natsort($nfopen); for ($n=0; $n<count($nfopen); $n++) { $place = each ($nfopen); fwrite($handle,"$place[value]"); } fclose($namesfilef); $filenmef = file.txt'; $handle = fopen($filenmef, 'w'); $namesfile = temp.txt"; $nfopen = file($namesfile); $nfopen = array_reverse($nfopen); foreach ($nfopen as $rank) { fwrite($handle,"$rank"); } fclose($namesfilef); ---- Server IP: 64.71.164.2 Probable Submitter: 68.18.65.182 ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- https://master.php.net/note/edit/93464 Del: integrated -- https://master.php.net/note/delete/93464/integrated Del: useless -- https://master.php.net/note/delete/93464/useless Del: bad code -- https://master.php.net/note/delete/93464/bad+code Del: spam -- https://master.php.net/note/delete/93464/spam Del: non-english -- https://master.php.net/note/delete/93464/non-english Del: in docs -- https://master.php.net/note/delete/93464/in+docs Del: other reasons-- https://master.php.net/note/delete/93464 Reject -- https://master.php.net/note/reject/93464 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160442) next »