Ich habe eine API, die angeforderte Bilder Pfade zum Frontend zurückgibt. Aber im Linux-Server braucht es natürliche Sortierung. Ich möchte natürliche Werte im yol
Schlüssel sortieren.Natürliche Sortierung zu mehrdimensionalen Array in PHP
$klein->respond('GET', '/getPaths/[:name]', function($request,$response) {
$path00 = "../manga/" . $request->name;
function getAll($path00)
{
$dirs = [];
foreach (new DirectoryIterator($path00) as $item) {
if (!$item->isDir() || $item->isDot()) {
continue;
}
$gedo = [];
$path01 = $path00 . "/" . $item;
$path02 = substr($path01, 3);
$yol = new DirectoryIterator($path01);
foreach ($yol as $esya) {
if (!$esya->isDot() && $esya->getFilename() !== ".DS_Store") {
$gedo[] = $path02 . "/" . $esya->getFilename();
}
}
$dirs[] = array('klasor' => $item->getFilename(), 'yol' => $gedo);
}
return $dirs; // Output its in the image.
};
$data = getAll($path00);
$response->json($data);
});
Ausgang:
Es gibt keine _question_ ist, was fragen Sie? –
Der Typ muss sein Array für eine bestimmte Reihe von Indizes natürlich sortieren und bittet uns, dies für ihn zu tun. – Code4R7