Examples of simple ways to replace key names in PHP

Source: Internet
Author: User
Tags yii

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!
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.