gpt4 book ai didi

PHP opendir 和 readdir 与数组目录(不是一个)

转载 作者:行者123 更新时间:2023-11-29 13:39:10 25 4
gpt4 key购买 nike

我有这个问题,我想对这个目录数组使用opendir,这可能吗?通过固定的 url,我可以使用 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/
等等

非常感谢

最佳答案

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

关于PHP opendir 和 readdir 与数组目录(不是一个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18338034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com