Home > Backend Development > PHP Tutorial > A small example of replacing array key names in PHP

A small example of replacing array key names in PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:54:58
Original
1841 people have browsed it
  1. /**
  2. * @todo Optimize EXCEL table output for YII query output with database table field names and key names
  3. * @todo Replace key names with 0, 1, 2...
  4. * @param array $data
  5. * @return array( 'excel_title'=array(),'excel_ceils'=array());
  6. */
  7. public function excelDataFormat($data){
  8. for ($i=0;$i$ each_arr=$data[$i];
  9. $new_arr[]=array_values($each_arr); //Return all key values ​​
  10. }
  11. $new_key[]=array_keys($data[0]); //Return all index values
  12. return array('excel_title'=>$new_key[0],'excel_ceils'=>$new_arr);
  13. }
Copy code

The author wrote this method purely to handle EXCEL export , if it is often used in the project, you can change the name!



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template