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
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:54:581850browse
  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!



Statement:
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