本文整理汇总了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;
}