連想配列のソートに関するサンプルプログラムを実装しました
$colors = ["red" => "赤","blue" => "青","yellow" => "黄"];
// 要素をキーで昇順に並び替える
ksort($colors);
foreach($colors as $key => $value){
echo "<p class='test1'> {$key}は日本語で{$value}です";
echo "<br>";
}
// 要素をキーで降順に並び替える
krsort($colors);
foreach($colors as $key => $value){
echo "<p class='test2'> {$key}は日本語で{$value}です";
echo "<br>";
}
Keyを昇順に並べるにはksort関数、降順に並べる場合はkrsort関数を使います。