php 多维数组转二维数组

array(3) {
  ["money"]=>
  string(6) "255.00"
  ["id"]=>
  string(1) "1"
  ["child"]=>
  array(1) {
    [0]=>
    array(3) {
      ["money"]=>
      string(6) "380.00"
      ["id"]=>
      string(1) "5"
      ["child"]=>
      array(2) {
        [0]=>
        array(2) {
          ["money"]=>
          string(4) "0.00"
          ["id"]=>
          string(1) "7"
        }
        [1]=>
        array(2) {
          ["money"]=>
          string(4) "0.00"
          ["id"]=>
          string(1) "4"
        }
      }
    }
  }
}

例如将多维数组转成二维数组:

$lis = array();
$liss['money'] = $list['money'];
$liss['id'] = $list['id'];
$lis[] = $liss;
$li = ssb($list['child']);
$lis = array_merge($lis,$li);

function ssb($aa){
    $sb = array();
    foreach($aa as $v){
        $arr = array();
        $arr['money'] = $v['money']; 
        $arr['id'] = $v['id']; 
        $sb[] = $arr;
        if($v['child']){
            $sbb = ssb($v['child']);
            $sb = array_merge($sb,$sbb);
        }
    }
    return $sb;
}

 

posted @ 2019-01-24 11:14  子焱  阅读(4167)  评论(0编辑  收藏  举报