What are the potential issues with using multiple arrays in PHP to store file names?
Using multiple arrays to store file names can lead to code duplication, increased complexity, and difficulty in maintaining the code. To solve this issue, you can use a multidimensional array to store file names, where each sub-array represents a different category of files.
// Define a multidimensional array to store file names
$files = [
'images' => ['image1.jpg', 'image2.jpg'],
'documents' => ['doc1.pdf', 'doc2.docx']
];
// Accessing file names
echo "Images: ";
foreach ($files['images'] as $image) {
echo $image . " ";
}
echo "\nDocuments: ";
foreach ($files['documents'] as $document) {
echo $document . " ";
}