読者です 読者をやめる 読者になる 読者になる

晴釣雨読

As the train goes through the mountain path, leaning on the lightcyan window, only I would think about my fun.

出会い

array_multisortがちゃんと回ってカワイイ(//▽//)

//例えば家計簿風に、キー=支出した人で、
//値=その支出の内容が更に配列で入ってるとして、
//年月日でソート。


$ary_1st['me'] = array('card','2016','4','15','clinic','priscription','4000');
$ary_1st['husband']
= array('cash','2014','9','21','bakery','cookies','5000');



$ary_1st['son'] = array('cash','2015','4','8','market','shirimps','3000');
$ary_1st['mother']
= array('cash','2016','12','4','florist','lilys','5000');

 

 


//人で取り出す
foreach($ary_1st as $who => $ary_2nd){

   //その人の各行を取り出してキー用に配列を誂える
   foreach ($ary_2nd as $key => $val){
      $ary_k行ey1[$key] = $val[1];//年
      $ary_key2[$key] = $val[2];//月
      $ary_key3[$key] = $val[3];//日
   }
   //年月日で昇順ソート
   array_multisort(
      $ary_key1, SORT_ASC,
      $ary_key2, SORT_ASC,
      $ary_key3, SORT_ASC,
      $ary_2nd
   );
   //書き出し方2種
   $ary_sorted_who[$who] = $ary_2nd;
   $ary_sorted_pay[$val[0]] = $ary_2nd;

}

print_r($ary_sorted_who);
print_r($ary_sorted_pay);

 

   Array
  (
  [mom] => Array
  (
  [0] => Array
  (
  [0] => cash
  [1] => 2016
  [2] => 1
  [3] => 4
  [4] => florist
  [5] => lilys
  [6] => 5000
  )
   
  [1] => Array
  (
  [0] => card
  [1] => 2016
  [2] => 7
  [3] => 1
  [4] => clinic
  [5] => priscription
  [6] => 4000
  )
   
  [2] => Array
  (
  [0] => cash
  [1] => 2016
  [2] => 10
  [3] => 4
  [4] => florist
  [5] => lilys
  [6] => 5000
  )
   
  [3] => Array
  (
  [0] => cash
  [1] => 2016
  [2] => 12
  [3] => 4
  [4] => florist
  [5] => lilys
  [6] => 5000
  )

 

ちゃんと回ってあな嬉し(//▽//)

画面をなでまわしたいwww

 

 

 

http://doremi.s206.xrea.com/php/tips/array.html

これ便利そう。csvの検索に使える。あとで読んどこ。