What is the best practice for creating a multidimensional array from CSV data in PHP?

When creating a multidimensional array from CSV data in PHP, it is best practice to read the CSV file line by line and then explode each line into an array using a delimiter (usually a comma). This allows you to easily structure the data into a multidimensional array where each row represents a new array within the main array.

$data = [];
$file = fopen('data.csv', 'r');

while (($line = fgetcsv($file)) !== false) {
    $data[] = $line;
}

fclose($file);

print_r($data);