从php中的foreach响应
在从file_get_contents函数中获取数据以在数组中添加数据。 然后,数据将其添加到XLSXWriter中。 看来对foreach的响应限制为100。 这是否可以改变,以便可能是更大的数量?
$data = file_get_contents("/home/user/testfile.json");
$json_obj = json_decode($data, true);
foreach ($json_obj['items'] as $order) {
$ordrenr = $order['id'];
$fornavn= $order['billingPerson']['firstName'];
$etternavn= $order['billingPerson']['lastName'];
$adresse = $order['billingPerson']['street'];
$postnr = $order['billingPerson']['postalCode'];
$sted = $order['billingPerson']['city'];
$mobil = $order['billingPerson']['phone'];
$epost = $order['email'];
$subtotal = $order['total'];
$bestilt = $order['createDate'];
$betalingstype = $order['paymentMethod'];
$fakturanr = $order['invoices'][0]['id'];
$fakturalink = $order['invoices'][0] ['link'];
$header = ['Ordrenr' => 'string',
'Fornavn' => 'string',
'Etternavn' => 'string',
'Adresse' => 'string',
'Postnr' => 'string',
'Sted' => 'string',
'Mobil' => 'string',
'Epost' => 'string',
'Bestilt' => 'string',
'OrdreSum Inkl MVA' => 'string',
'Betalingtype' => 'string',
'Faktura nr' => 'string',
'Ordreskjema' => 'string' ];
$rows[] = [$ordrenr, $fornavn, $etternavn, $adresse , $postnr, $sted , $mobil, $epost, $bestilt, $subtotal, $betalingstype , $fakturanr, $fakturalink];
}
$structure = "/home/user/testfolder/";
if (!file_exists ($structure))
{
mkdir($structure, 0777, true);
}
$writer = new XLSXWriter();
$writer->setAuthor('Author');
$writer->writeSheet($rows, 'SHEETNAME', $header);
$writer->writeToFile("/home/user/testfolder/" . "April_". "$from". "_data.xlsx" );
In fetching data from file_get_contents function to add the data in array.
The data then added to excel with XLSXWriter.
It looks like the respond to foreach is limited to 100.
Is this possible to change so it could be a larger amount?
$data = file_get_contents("/home/user/testfile.json");
$json_obj = json_decode($data, true);
foreach ($json_obj['items'] as $order) {
$ordrenr = $order['id'];
$fornavn= $order['billingPerson']['firstName'];
$etternavn= $order['billingPerson']['lastName'];
$adresse = $order['billingPerson']['street'];
$postnr = $order['billingPerson']['postalCode'];
$sted = $order['billingPerson']['city'];
$mobil = $order['billingPerson']['phone'];
$epost = $order['email'];
$subtotal = $order['total'];
$bestilt = $order['createDate'];
$betalingstype = $order['paymentMethod'];
$fakturanr = $order['invoices'][0]['id'];
$fakturalink = $order['invoices'][0] ['link'];
$header = ['Ordrenr' => 'string',
'Fornavn' => 'string',
'Etternavn' => 'string',
'Adresse' => 'string',
'Postnr' => 'string',
'Sted' => 'string',
'Mobil' => 'string',
'Epost' => 'string',
'Bestilt' => 'string',
'OrdreSum Inkl MVA' => 'string',
'Betalingtype' => 'string',
'Faktura nr' => 'string',
'Ordreskjema' => 'string' ];
$rows[] = [$ordrenr, $fornavn, $etternavn, $adresse , $postnr, $sted , $mobil, $epost, $bestilt, $subtotal, $betalingstype , $fakturanr, $fakturalink];
}
$structure = "/home/user/testfolder/";
if (!file_exists ($structure))
{
mkdir($structure, 0777, true);
}
$writer = new XLSXWriter();
$writer->setAuthor('Author');
$writer->writeSheet($rows, 'SHEETNAME', $header);
$writer->writeToFile("/home/user/testfolder/" . "April_". "$from". "_data.xlsx" );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,以上代码应排除在foreach循环中。
其次,您是否获得执行时间限制超过错误或什么?
如果是,则可以通过在PHP中设置MAX_EXECTURE来增加限制。
First, the above code should be exclude from foreach loop.
Secondly, are you getting an execution time limit exceed error or what?
If yes, then you can increase limit by set max_execution in php.