How can you create a multidimensional array from a CSV file in PHP?
When working with CSV files in PHP, you may need to convert the data into a multidimensional array for easier manipulation. To achieve this, you can use the `fgetcsv()` function to read each row of the CSV file and store it as an array. You can then push each row array into a parent array to create the multidimensional structure.
// Open the CSV file for reading
$file = fopen('data.csv', 'r');
// Initialize an empty array to store the data
$data = [];
// Loop through each row in the CSV file
while (($row = fgetcsv($file)) !== false) {
// Push each row into the data array
$data[] = $row;
}
// Close the file
fclose($file);
// Output the multidimensional array
print_r($data);