這很有趣,沒有讓我感到難過。我有一個名爲Workday的'order'對象數組,如果我print_r數組,我會得到以下內容;PHP Array沒有正確迭代,只抓取第一個結果
Workday Object
(
[workday] => Array
(
[0] => Order Object
(
[id] => 3
[date] => 2013-08-02
[username] => userXYZ
[number] => 33333333
[duration_start] => 20:51:00
[duration_end] => 21:51:00
[total] => $340.00
)
[1] => Order Object
(
[id] => 3
[date] => 2013-08-03
[username] => userXXA
[number] => 87653212
[duration_start] => 10:51:00
[duration_end] => 11:54:00
[total] => $20.00
)
[2] => Order Object
(
[id] => 3
[date] => 2013-08-01
[username] => userXYD
[number] => 12345678
[duration_start] => 08:37:00
[duration_end] => 10:01:00
[total] => $10.00
)
)
)
這個問題似乎是當我嘗試迭代數組時,它只輸出第一個結果。我錯過了什麼?
$workday = new Workday();
$workday->Get($username, $duration_start, $duration_end);
$i = 0;
if($workday != null)
{
foreach($workday as $orders)
{
echo "ID: " . $orders[$i]->number;
$i++;
}
}
剛試過,有致命錯誤:你確定這是不是你的'獲得()'方法,返回結果只有一個不能使用類型爲工作日的對象數組 – devfunkd
?你是否將'$ username,$ duration_start,$ duration_end'作爲搜索參數傳遞,因爲這可能會增加你爲什麼只收到一個結果。 –
@DaveChen你的回答是正確的,你爲什麼刪除它? – anubhava