How can you create a multidimensional array from data extracted from a .txt file in PHP?
When extracting data from a .txt file in PHP, you can create a multidimensional array by reading the file line by line and splitting each line into an array of values. You can then push these arrays into a parent array to form the multidimensional structure.
$data = array();
$file = fopen("data.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
$values = explode(",", $line);
$data[] = $values;
}
fclose($file);
}
print_r($data);