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

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.