1. 程式人生 > >php二維陣列轉陣列

php二維陣列轉陣列

1.轉陣列

$hb=Db::table('sl_details')->where(['hid'=>$id])->where('pid','<>',0)->field('pid,moeny')->select();
            $arra = [];
            foreach ($hb as $k=>$v){
                $arra[$k] = $v['pid'];
            }

dump($hb); array (size=2) 0 => array (size=2) ‘pid’ => int 2 ‘moeny’ => string ‘1.57’ (length=4) 1 => array (size=2) ‘pid’ => int 1 ‘moeny’ => string ‘0.96’ (length=4)

dump($arra); array (size=2) 0 => int 2 1 => int 1

2.轉字串

 $nid= Db::table('news')->field('id')->select();
            foreach ($nid as $v){
                $v = join($v);
                $temp[] = $v;
            }
            $t = "";
            foreach ($temp as $v){
                $t
.="".$v."".","; } $aa=substr($t,0, -1);