How can PHP arrays be effectively used to store and retrieve data from multiple text files?

When dealing with multiple text files, PHP arrays can be effectively used to store and retrieve data by reading the contents of each text file and storing them as elements in the array. This allows for easy access to the data from each file and simplifies the process of managing and manipulating the information stored in the text files.

<?php
// Array to store data from text files
$data = [];

// Read contents of text files and store in array
$files = ['file1.txt', 'file2.txt', 'file3.txt'];
foreach ($files as $file) {
    $content = file_get_contents($file);
    $data[$file] = $content;
}

// Retrieve data from array
echo $data['file1.txt']; // Output contents of file1.txt
?>