루프에 중첩 된 루프가 있습니다. 두 번째 루프에 도달 할 때까지 모든 데이터가 잘 표시되고 반환 된 데이터가 반복적으로 유지됩니다. 두 번째 루프의 항목의 노래가 15 번 반복되는 지점에 도달합니다.PHP foreach 루프 중첩 반복 증가
항목 는 항목 이 -subitems
이
항목 이 가 이
항목 이 -subitems 이 -subitems을 -subitems -subitems -subitems -subitems -subitems -subitems -subitems
내 루프를 정리하라는 지시를 받았지만이를 수행하는 방법은 확실합니다. 어떤 아이디어? 보기 소스 : http://mixtapemonkey.com/json
<?php
include ("connection.php");
foreach($db->query("SELECT * FROM mixtapes WHERE year='2014' OR year = '2015' ORDER BY id DESC LIMIT 24") as $info) {
echo "mixtape-".$info['id']," {\n";
echo "\t\"id\" : \"".$info['id']."\",\n";
echo "\t\"title\" : \"".$info['title']."\",\n";
echo "\t\"name\" : \"".$info['name']."\",\n";
echo "\t\"genre\" : \"".$info['genre']."\",\n";
echo "\t\"year\" : \"".$info['year']."\",\n";
echo "\t\"downloads\" : \"".$info['downloads']." Downloads\",\n";
echo "\t\"thumb\" : \"http://mixtapemonkey.com/".$info['thumb']."\",\n";
echo "\t\"songs\" : {\n";
if ($handle = opendir("mixtapes/zip/".$info['id'])) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "mixtapes/zip/".$info['id'] && $entry != "mixtapes/zip/".$info['id']) {
if ($newhandle = opendir("mixtapes/zip/".$info['id']."/".$entry)) {
while (false !== ($newentry = readdir($newhandle))) {
if ($newentry != "mixtapes/zip/".$info['id']."/".$entry && $newentry != "mixtapes/zip/".$info['id']."/".$entry) {
$ext = substr($newentry, strrpos($newentry, '.') + 1);
if ($ext == "mp3" || $ext == "m4a")
{
$item = "mixtapes/zip/".$info['id']."/".$entry."/";
$musicarray[] = $newentry;
sort($musicarray);
}
}
}
closedir($newhandle);
}
}
}
closedir($handle);
}
foreach ($musicarray as $song) {
echo "\t\t\"track\" : \"http://mixtapemonkey.com/$item$song\",\n";
}
echo "\t}\n";
echo "},\n\n";
}?>
하위 항목의 깊이를 모르면 어떤 플래그로 식별하고 RECURSION을 수행하십시오. – TNC
@TNC 무엇? 나를 위해 그것을 부셔 라. 나는 이것에 대해 새로운이야. –
내가 말하고자하는 것은 하위 항목에 계층 적 트리 형성에 대한 명확한 비전을 갖고 있어야하며 역순으로 트래버스해야한다는 것입니다. 확실히 회복. – TNC