What are common methods for reading and sorting data from a text file in PHP?

When reading and sorting data from a text file in PHP, common methods include using file_get_contents() to read the file contents into a string, explode() or preg_split() to split the string into an array of lines or values, and sorting functions like sort() or asort() to sort the data as needed.

// Read the contents of the text file into a string
$file_contents = file_get_contents('data.txt');

// Split the string into an array of lines
$data_array = explode("\n", $file_contents);

// Sort the data array alphabetically
sort($data_array);

// Output the sorted data
foreach ($data_array as $line) {
    echo $line . "\n";
}