ホームページ >バックエンド開発 >PHPチュートリアル >PHP 初心者の配列ソリューションは、特定のキー値 100 に基づいて配列を並べ替えます。
こんなjson配列
[ {"id":"1","name":"21g","dis":"33"},
{"id":"2","name":"21g" ,"dis":"22"},
{"id":"3","name":"21g","dis":"3"},
{"id":"4","name" :"21g","dis":"5"},
{"id":"5","name":"21g","dis":"12"}]
小さいものから大きいものまで並べ替える必要がありますdis によると
[{"id":"3","name":"21g","dis":"3"},
{"id":"4","name":"21g"," dis": "5"},
{"id":"5","name":"21g","dis":"12"},
{"id":"2","name":" 21g", "dis":"22"},
{"id":"1","name":"21g","dis":"33"}]
手順の詳細を問い合わせてください オンラインで待っています 至急! ! !
$s =<<< TXT[ {"id":"1","name":"21g","dis":"33"}, {"id":"2","name":"21g","dis":"22"}, {"id":"3","name":"21g","dis":"3"}, {"id":"4","name":"21g","dis":"5"}, {"id":"5","name":"21g","dis":"12"}] TXT;$a = json_decode($s, true);foreach($a as $v) $r[] = $v['dis'];array_multisort($r, $a);echo json_encode($a);[{"id":"3","name":"21g","dis":"3"},{"id":"4" ,"名前":"21g","ディス":"5"},{"id":"5","名前":"21g","ディス":"12"},{"id":" 2","name":"21g","dis":"22"},{"id":"1","name":"21g","dis":"33"}]
ありがとうありがとうございます! !完了しました!