PHP 纵向数组转横向

 /**
     * select 查询数据结果集 纵向数组横向排
     */
    function aryy_x($ary) {
        $ary2 = array(); //返回数组
        $column = array();
        foreach ($ary[0] as $k => $v) {
            $column[] = $k; //字段名
        }
        $arylength = count($ary); //总公多少数据
        $columnlength = count($column); //总公多少字段
        for ($i = 0; $i < $columnlength; $i++) {
            $value = array();
            for ($j = 0; $j < $arylength; $j++) {
                $value[] = $ary[$j][$column[$i]]; //竖排集合
            }
            $ary2[$column[$i]] = $value; //竖排集合 -- 以列名 作为键值
        }
        return $ary2;
    }

猜你喜欢

转载自blog.csdn.net/Purgatory001/article/details/81286174