这是我的API中的while循环。
while($r = $stmt->fetch(PDO::FETCH_ASSOC) ) {
$nArray[] = array('bolumismi' => $r['bolumismi'], 'klasor' => $r['klasor'], 'yol' => explode(",", $r['yol']));
}
我想对yol
数组进行自然排序。我调查了它,我想我需要使用array_multisort
,但我无法弄清楚如何?我的数组的当前JSON输出:
[
{
"bolumismi": "",
"klasor": "114",
"yol": [
"mangas\/Gamaran\/114\/0.jpg",
"mangas\/Gamaran\/114\/019.jpg"
]
},
{
"bolumismi": "",
"klasor": "113",
"yol": [
"mangas\/Gamaran\/113\/0.jpg",
"mangas\/Gamaran\/113\/1.jpg",
"mangas\/Gamaran\/113\/10.jpg",
"mangas\/Gamaran\/113\/11.jpg",
"mangas\/Gamaran\/113\/12.jpg",
"mangas\/Gamaran\/113\/13.jpg",
"mangas\/Gamaran\/113\/14.jpg",
"mangas\/Gamaran\/113\/15.jpg",
"mangas\/Gamaran\/113\/16.jpg",
"mangas\/Gamaran\/113\/17.jpg",
"mangas\/Gamaran\/113\/18.jpg",
"mangas\/Gamaran\/113\/2.jpg",
"mangas\/Gamaran\/113\/3.jpg",
"mangas\/Gamaran\/113\/4.jpg",
"mangas\/Gamaran\/113\/5.jpg",
"mangas\/Gamaran\/113\/6.jpg",
"mangas\/Gamaran\/113\/7.jpg",
"mangas\/Gamaran\/113\/8.jpg",
"mangas\/Gamaran\/113\/9.jpg"
]
}
]
答案 0 :(得分:1)
会解决这个问题吗?
while($r = $stmt->fetch(PDO::FETCH_ASSOC) ) {
$yol = explode(",", $r['yol']);
natcasesort($yol);
$nArray[] = array(
'bolumismi' => $r['bolumismi'],
'klasor' => $r['klasor'],
'yol' => $yol
);
}