For example I have a build.json file below. Contains a basic folder / file structure I made up created in JSON.
{
"folders": [
{
"name": "folder-a",
"files": [
{
"name": "file-a.html"
},
{
"name": "file-b.html"
}
],
"folders": [
{
"name": "sub-folder-a",
"files": [
{
"name": "sub-file-a.html"
},
{
"name": "sub-file-b.html"
}
]
}
]
},
{
"name": "folder-b",
"files": [
{
"name": "file-a.html"
},
{
"name": "file-b.html"
}
]
}
]
}
Now I created the simple PHP code below, which can loop through the first parts of the array. Then of course if I keep making foreach loops inside of the first foreach, I can keep going through the array. The problem is that I have no idea how many folders / files there will be in the array. Any ideas on how I can just keep looping without knowing how many times to loop? Thanks!
$json = file_get_contents('build.json');
$decode = json_decode($json);
foreach($decode as $key => $val){
foreach($val as $valKey => $data){
var_dump($data);
}
}