How can PHP functions like str_getcsv and asort be utilized effectively when processing CSV data for specific tasks?

When processing CSV data in PHP, functions like str_getcsv can be used to parse the CSV data into an array for easier manipulation. Additionally, functions like asort can be utilized to sort the data based on specific criteria. By combining these functions effectively, you can process CSV data efficiently for tasks such as sorting, filtering, or extracting specific information.

// Sample CSV data
$csvData = "John,Doe,30\nJane,Smith,25\nAlice,Johnson,35";

// Parse CSV data into array
$dataArray = array_map('str_getcsv', explode("\n", $csvData));

// Sort the data by age
usort($dataArray, function($a, $b) {
    return $a[2] - $b[2];
});

// Output sorted data
foreach ($dataArray as $row) {
    echo implode(',', $row) . "\n";
}