I am trying to append filenames to an array in PHP. I have code which reads filenames from a directory "songs" on a server. I simply want each of these filenames to be added to an array. How could I do this?
Here is my PHP.
$target = "songs/";
$items = array();
if ($handle = opendir($target)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
foreach($song as $entry) {
$items[] = $entry;
}
//echo $items;
echo $entry."\n";
}
}
closedir($handle);
}
foreach($song as $entry)What is$song?$entryfor the filename and inforeach ($song as $entry). So after the loop,$entrycontains the last element of$song, not the filename.