The default output, the database field name is the key to the array of keys output, but the data with the key is not able to meet the unknown operation, here are a good way to solve this problem
The database operation function encapsulated in the YII framework, the default output, the database field name is the key to the array of keys output, but sometimes with the key name of the data can not meet the operation of unknown circumstances, such as: the database data exported to Excel, such as more unusual operations. So this side needs to parse the database result set, the following is a simple method for this particular case: the code is as follows:/** * @todo for yii query output with database table field name Key name to optimize Excel table output * @todo replace key name 0, 1, 2 ... * @param array $data * @return Array (' Excel_title ' =array (), ' Excel_ceils ' =array ()); * * Public Function Exceldataformat ($data) {for ($i =0; $i <count ($data); $i + +) {$each _arr= $data [$i]; $new _arr[]=array_values ($each _arr); Returns all key values} $new _key[]=array_keys ($data [0]); Returns all index value return array (' Excel_title ' => $new _key[0], ' excel_ceils ' => $new _arr); Here the author writes This method is purely for processing Excel to export uses, if in the project frequently uses, may change a name again Yo!