当前位置: 首页>>代码示例>>PHP>>正文


PHP CSV::to_array方法代码示例

本文整理汇总了PHP中CSV::to_array方法的典型用法代码示例。如果您正苦于以下问题:PHP CSV::to_array方法的具体用法?PHP CSV::to_array怎么用?PHP CSV::to_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSV的用法示例。


在下文中一共展示了CSV::to_array方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load_data

 /**
  This functions loads the data related to each page or layout
  for a page we load all files in the related directory
  for a layout we check the "datas-sources" attribute of our layout_file.json and load them
  In your real world application you can load data only when it is needed according to each page inside controllers
 */
 private function load_data($data_dir)
 {
     $data_files = array();
     $format = "/([0-9a-z\\-_]+)\\.(json|csv)\$/i";
     //see if there's a folder for partial data relating to this page or layout
     //if so iterate all json/csv files and load the data
     $partial_data_folder = "{$data_dir}/{$this->type}s/partials/{$this->name}";
     $stats = null;
     if (is_dir($partial_data_folder)) {
         $files = scandir($partial_data_folder);
         foreach ($files as $name) {
             if ($name == '.' or $name == '..') {
                 continue;
             }
             if (!preg_match($format, $name, $filename)) {
                 continue;
             }
             $data_files[$filename[1]] = "{$partial_data_folder}/{$name}";
         }
     }
     foreach ($data_files as $var_name => $var_value) {
         $new_data = '';
         if (preg_match("/\\.json\$/i", $data_files[$var_name])) {
             $new_data = json_decode(file_get_contents($data_files[$var_name]), TRUE);
         } else {
             if (preg_match("/\\.csv\$/i", $data_files[$var_name])) {
                 //load csv data into an array
                 $new_data = CSV::to_array($data_files[$var_name]);
                 foreach ($new_data as &$data) {
                     if (isset($data['status'])) {
                         $data[$data['status']] = true;
                     }
                 }
             }
         }
         $this->vars[str_replace('.', '_', $var_name)] = $new_data;
         //here we replace '.' with '_' in variable names, so template compiler can recognize it as a variable not an object
         //for example change sidebar.navList to sidebar_navList , because sidebar is not an object
     }
     return true;
 }
开发者ID:12liuxiangyu12,项目名称:bitles,代码行数:47,代码来源:Page.php


注:本文中的CSV::to_array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。