带有数组目录的PHP opendir和readdir(不是一个)

时间:2013-08-20 14:44:39

标签: php mysql arrays readdir opendir

我有这个问题,我想在这个目录数组中使用opendir,这有可能吗?使用固定网址,我可以使用readdir读取文件。但我不知道如何处理多个目录...
创建数组:

$results = mysqli_query($connecDB,"SELECT * FROM brands WHERE 1 IN (php, ruby, java) ORDER BY id ASC");

//select all records with value "1" in different columns "php ruby java".
// The value "1" indicates a folder created named $id in php, ruby and/or java folder

$resultsArray = array();

while($row = mysqli_fetch_assoc($results)){
    if($row['php'] == 1) {
        $resultsArray['php'][] = $row['id'];
    }
    if($row['java'] == 1) {
        $resultsArray['java'][] = $row['id'];
    }
    if($row['ruby'] == 1) {
        $resultsArray['ruby'][] = $row['id'];
    }
}

foreach($resultsArray as $language => $array){
    echo "url/" . $language . "/" . $row['id'] . "<br>";
}

输出示例:
url / php / 1 /
url / java / 1 /


url / php / 2 /
url / ruby​​ / 2 /
url / java / 2 /


url / php / 3 /


url / php / 4 /
url / ruby​​ / 4 /


非常感谢你

2 个答案:

答案 0 :(得分:1)

foreach($resultsArray as $language => $array){
    foreach(array_slice(glob('work/'.$language.'/'.$rowtest['id'].'/*.jpg'),0,1) as $image){    
        echo $image . "<br />";
    }
}

答案 1 :(得分:0)

您可以在foreach循环中一个接一个地读取目录。究竟是什么问题?