How can PHP arrays be effectively used to sort and manipulate data from a file?

To sort and manipulate data from a file using PHP arrays, you can read the file contents into an array, perform sorting operations using built-in array functions, and manipulate the data as needed. This can be achieved by reading the file line by line, exploding each line into an array, and then sorting or manipulating the data based on your requirements.

<?php
// Read file contents into an array
$fileData = file('data.txt', FILE_IGNORE_NEW_LINES);

// Sort the array
sort($fileData);

// Manipulate the data
foreach ($fileData as $line) {
    $data = explode(',', $line);
    // Perform manipulation operations here
}

// Output the manipulated data
foreach ($fileData as $line) {
    echo $line . PHP_EOL;
}
?>