2
3

More than 1 year has passed since last update.

連想配列のソートに関するサンプルプログラムを実装しました

   $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関数を使います。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3