从php中的foreach响应

发布于 2025-01-23 17:17:35 字数 1639 浏览 3 评论 0原文

在从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2025-01-30 17:17:35
$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' ]; 

首先,以上代码应排除在foreach循环中。
其次,您是否获得执行时间限制超过错误或什么?
如果是,则可以通过在PHP中设置MAX_EXECTURE来增加限制。

ini_set('max_execution_time', '0');
$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' ]; 

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.

ini_set('max_execution_time', '0');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文