Is there a way I can name an array before adding it to a group of arrays? I have the code below that gets a list of files from a dir, then gets the contents of the files listed and adds them to an array.
public function buildArray(){
$handsetFilenames = array();
$handsetArray = array();
if ($handle = opendir('path to file/')) {
while (false !== ($entry = readdir($handle))) {
$handsetFilenames[] = $entry;
}
}
foreach ($handsetFilenames as $match => $key){
$file = file('handsets/'.$key);
$handsetArray[] = $file;
}
return $handsetArray;
}
When I output the $hansetArray I get a list just saying Array 23 times. When I output the arrays within the array they work fine, but i’d like them to be named after the file they’re taken from i.e. the list from $handsetFilenames.
Edit: Apparently I’m not showing I’ve tried to solve this myself!!
I have tried to add this $handsetArray[$key] = $file; to make it an associate array, but this does still not work.
My output method is this:
$file_location = $fileLocation->buildArray();
foreach ($file_location as $match => $key){
$page->addToBody($match.' = '.$key."</br>");
}
Do the following: