How can the array_push function be used to add a new record to the end of a CSV file in PHP?

To add a new record to the end of a CSV file in PHP using the array_push function, you first need to read the existing CSV file into an array, then push the new record to the array, and finally write the updated array back to the CSV file.

// Read the existing CSV file into an array
$csvFile = 'data.csv';
$records = array_map('str_getcsv', file($csvFile));

// New record to be added
$newRecord = ['John Doe', '30', 'New York'];

// Add the new record to the end of the array
array_push($records, $newRecord);

// Write the updated array back to the CSV file
$fp = fopen($csvFile, 'w');
foreach ($records as $record) {
    fputcsv($fp, $record);
}
fclose($fp);