By turning a file into an array you can work with the data within it as you would a standard array.
<?php
$file = file('names.txt');
foreach($file as $line_num => $line) {
print "$line_num: $line</br>";
}
print "</br>";
sort($file);
foreach($file as $line_num => $line) {
print "$line_num: $line</br>";
}
?>
Be the first to comment