我必须制作一个以这种方式工作的 csv 文件:
Row 1 --> Text Data
Row 2 --> Person Information
Row 3 --> Products information
Row1 和 Row2 已完成,我已经正确编写了代码。
该ROW3是一个问题becasue需要给我带回一排每一个产品,他们所有的数据。
我怎样才能写出代码的方式?目前我已经写了这个,但 row3 是空的。
$list = array (
array ('Order id', 'Billing Name' , 'Product Title', 'Total Price' ),
array ($order->id, $order->firstname, '', ''),
$listProd = array(),
);
$listProd = array();
foreach ($order->products as $product) {
$listProd = array (
$order->id,
'',
$product->title,
$cart->renderPriceAndCurrency($product->pad_price),
);
}
$local_file = fopen('php://temp', 'r+');
foreach ($list as $row) {
fputcsv($local_file, $row);
}
rewind($local_file);
谢谢你。
$list = array (
array ('Order id', 'Billing Name' , 'Product Title', 'Total Price' ),
array ($order->id, $order->firstname, '', ''),
$listProd = array(), // this does __nothing__ except adding empty array to `$list`
);
替换为:
$list = array (
array ('Order id', 'Billing Name' , 'Product Title', 'Total Price' ),
array ($order->id, $order->firstname, '', ''),
);
foreach ($order->products as $product) {
$list[] = array (
$order->id,
'',
$product->title,
$cart->renderPriceAndCurrency($product->pad_price),
);
}
在这里,您将每个产品项目添加到$list
数组的末尾。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句