How can the content of a file be sorted in PHP?

To sort the content of a file in PHP, you can read the file into an array, sort the array using a sorting function, and then write the sorted content back to the file. This can be done using functions like file(), sort(), and file_put_contents().

// Read the content of the file into an array
$content = file('file.txt');

// Sort the array
sort($content);

// Write the sorted content back to the file
file_put_contents('file.txt', implode("\n", $content));