2014-01-20 72 views
-1

我需要從以下每個STDClass對象中提取ShipQty並將其插入到一個新數組中。從STDClass對象獲取值並創建新的數組

Array ([0] => stdClass Object ([PRODUCTID] => 2 [ORDERID] => 7 [SHIPQTY] => 3 [STATUS] => 1 [SHIPDATE] => 2013-12-18) [1] => stdClass Object ([PRODUCTID] => 2 [ORDERID] => 5 [SHIPQTY] => 2 [STATUS] => 1 [SHIPDATE] => 2014-01-02) [2] => stdClass Object ([PRODUCTID] => 2 [ORDERID] => 2 [SHIPQTY] => 5 [STATUS] => 1 [SHIPDATE] => 2014-01-08) [3] => stdClass Object ([PRODUCTID] => 2 [ORDERID] => 1 [SHIPQTY] => 2 [STATUS] => 1 [SHIPDATE] => 2014-01-16)) 

我想以下幾點:array(3,2,5,2)

預先感謝您!

+0

請告訴我們你到目前爲止所嘗試過的。 – Luceos

+0

@Luceos我已經試過了Emissary在下面發佈的內容,但是無法讓它工作。 – user2436953

回答

1

試試這個(假設你的數組被命名爲$ myArr,該):

$result = array(); 
foreach ($myArr as $obj) { 
    $result[] = $obj->SHIPQTY; 
} 

希望這有助於。