日付順にソートしたいのですがうまくできません
下記のように並び変えたいですがどこが間違っているのでしょうか?
array(1) { ["date"]=> array(3) { ["2022/10"]=> string(1) "a" ["2022/08"]=> string(1) "a" ["2021/09"]=> string(1) "a" } }
<?php $date["date"]["2022/08"]="a"; $date["date"]["2021/09"]="a"; $date["date"]["2022/10"]="a"; $sortKey = array(); foreach ($date["date"] as $index => $val) { $sortKey[$index] = $date["date"][$index]; } array_multisort($sortKey, SORT_DESC, $date["date"]); var_dump($date); ?>
どのような結果になったのでしょうか?
foreach の中で、 $index と $val を var_dump や print_r 等を使って表示してみると想定する内容になっていますか?
回答1件
あなたの回答
tips
プレビュー