PHP Foreach循环停止迭代中的几个循环

时间:2016-05-09 10:38:07

标签: php arrays wordpress foreach

我有一个函数调用,它返回带有嵌套对象的以下数组。

$customerTransactionsSummary = tickethut_get_red61via_customer_transactions_summary();

结果:

Array
(
    [0] => viaApiTransactionSummary Object
        (
            [orderId] => 4139:2841
            [title] => 4139:DIONVN:110514:174803835IB
            [date] => 2014-05-11 17:48:45
        )

    [1] => viaApiTransactionSummary Object
        (
            [orderId] => 4139:4686
            [title] => 4139:WEB001:310514:164913426OS
            [date] => 2014-05-31 16:50:39
        )

    [2] => viaApiTransactionSummary Object
        (
            [orderId] => 4139:4892
            [title] => 4139:WEB001:020614:171508714RB
            [date] => 2014-06-02 17:15:08
        )

    [3] => viaApiTransactionSummary Object
        (
            [orderId] => 4139:6445
            [title] => 4139:WEB001:160614:155254808MA
            [date] => 2014-06-16 16:05:27
        )
        (...)

然后我创建了一个foreach循环,它使用 orderId title 项并将它们传递给另一个函数。

//fetch the order summary:
foreach ($customerTransactionsSummary as $customerTransactionSummary) { 
    $orderSummary = tickethut_get_red61via_order_summary($customerTransactionSummary->orderId, $customerTransactionSummary->title);
}

如果我在foreach循环中输出 $ customerTransactionSummary ,它会在18次迭代后停止。

$counter = 1;
foreach ($customerTransactionsSummary as $customerTransactionSummary) { 

echo $counter;
$counter++;

$orderSummary = tickethut_get_red61via_order_summary($customerTransactionSummary->orderId, $customerTransactionSummary->title);

}

有人知道造成这种情况的原因吗?

0 个答案:

没有答案