Posts: 1,832
Location: Somewhere else entirely
|
Your array $entries is being overwritten every time around the loop, so the inner loop only ever sees one value at a time. Separate out the loops so that one builds the array completely, put a sort in between and then let the second loop display them:
PHP Code:
if (!is_file("Test.txt")) { die(""); } $file_contents = file("Test.txt"); $entries = array(); foreach($file_contents as $key=>$value){ if($value != ""){ $entry = explode("|", $value); $entries[] = $entry[10]; } } rsort($entries, SORT_NUMERIC); foreach($entries as $key=>$val){ print "$val <br>"; }
Some explanation:
$entries = Array(); creates a blank array that the loop then fills. The syntax $entries[] means 'the next available index in $entries', so the first loop fills the array $entries with successive data items from the 10th column of the file. Also you can use $value in the first loop instead of indexing the array each time.
I use rsort here instead of arsort - $entries now has numeric keys and rsort ensures the values come out sorted when you loop through them.
The final loop should print out the values in order.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
Last edited by 0beron; 11-28-2005 at 06:35 PM..
|