當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。