Şöyle bir dosya yapısı var.
-Manga
     -Berserk
          -345
          -346
     -One Piece
          -840
          -841

Manga dosyası altında bir sürü alt klasör ve bu alt klasörlerin altındada bir sürü numaralandırılmış klasörler var. Amacım şu Berserk veya One Piece klasörünün altında ki en büyük klasörü bulmak. JSON olarak ifade edersek:


[
    {"name":"Berserk","last":346},
    {"name":"One Piece","last":841}
]
Sınırlı php bilgimle ve biraz araştırarak aşağıdaki birşey elde ettim ama sadece isimleri veriyor.


function getAll($path)
{
    $dirs = [];
    foreach (new DirectoryIterator($path) as $item) {
        if (!$item->isDir() || $item->isDot()) {
            continue;
        }
        if ($max = getMaxInDir($item->getRealPath())) {
            $dirs[] = [
                'name' => $item->getFilename(),
                'last' => $max,
            ];
        }
    }
    return $dirs;
}

function getMaxInDir($path)
{
    $max = 0;
    foreach (new DirectoryIterator($path) as $item) {
        $name = $item->getFilename();
        if (!$item->isDir() || $item->isDot() || !is_numeric($name)) {
            continue;
        }
        if (($current = (int)$name) > $max) {
            $max = $current;
        };
    }

    return $max;
}
echo json_encode(getAll($path));