if (count($dataRows)) {
// 自定义字段数量
$column_length = req_int_strict('column_length');
$a = array();
foreach ($dataRows as $i => $row) {
$js = __ROOTPATH__."/js/$row[id].js";
if (file_exists($js)) {
$js = json_decode(file_get_contents($js),true);
// 自定义字段数量必须和要导出的数据字段相等
if (isset($js['goods']['data']) && count($js['goods']['data']) === $column_length) {
$b = array();
foreach ($js['goods']['data'] as $i => $data) {
// 在数组第一行插入带键值的元素
if ($i === 0) {
$b[] = array('col' => '名称','val' => $row['name']);
}
$b[] = $data;
}
$a[] = $b;
}
}
}
if (count($a)) {
exit(json_encode($a));
}
}
在数组第一行插入带键值的元素,内置函数 array_unshift 不好使,第一次循环中插入即可。
于 2023-10-17 19:54:06 首次发布