2012-09-09 30 views
-1

我想從此數組中檢索數量。如何從PHP對象數組中檢索項目?

invoice Object 
    (
    [data:private] => Array 
    (
    [i_status] => pend 
    [i_title] => 500 HLCoins , 500 HLCoins x8 
    [i_member] => 1 
    [i_items] => Array 
    (
    [0] => Array 
    (
    [act] => new 
    [app] => nexus 
    [type] => product 
    [cost] => 0 
    [tax] => 0 
    [renew_term] => 0 
    [renew_units] => 
    [renew_cost] => 0 
    [quantity] => 1 
    [physical] => 
    [shipping] => Array 
    (
    ) 
    [weight] => 0 
    [itemName] => 500 HLCoins 
    [itemID] => 3 
    [cfields] => Array 
    (
    ) 
    [extra] => 
    [opt_id] => 0 
    [associated] => 
    [assocBought] => 
    [groupRenewals] => 0 
    [methods] => Array 
    (
    ) 
    [k] => 0 
    [_tax] => 0 
    ) 
    [1] => Array 
    (
    [act] => new 
    [app] => nexus 
    [type] => product 
    [cost] => 0 
    [tax] => 0 
    [renew_term] => 0 
    [renew_units] => 
    [renew_cost] => 0 
    [quantity] => 8 
    [physical] => 
    [shipping] => Array 
    (
    ) 
    [weight] => 0 
    [itemName] => 500 HLCoins 
    [itemID] => 3 
    [cfields] => Array 
    (
    ) 
    [opt_id] => 0 
    [groupRenewals] => 0 
    [methods] => Array 
    (
    ) 
    [_tax] => 0 
    ) 
    ) 
    [i_total] => 0 
    [i_date] => 1347217384 
    [i_return_uri] => 
    [i_paid] => 0 
    [i_status_extra] => a:1:{s:4:"type";s:4:"zero";} 
    [i_discount] => 0 
    [i_temp] => 
    [i_ordersteps] => 0 
    [i_noreminder] => 1 
    [i_renewal_ids] => Array 
    (
    ) 
    [i_po] => 
    [i_notes] => 
    [i_shipaddress] => 
    [i_id] => 229 
    ) 


     [takeAction] => 1 
    ) 

我已經嘗試了一堆代碼量像$ invoice->的,$發票[1] - >量,這$ - > $ invoice->的數量,但他們都不顯示。

它仍然不顯示,我試圖print_r,這是它給了我的數組。

+0

你有多個數組。你想要哪一個? –

+1

看起來像* everything *被封裝在'$ data'屬性下。有意思... ...一個功能 公共職能onPurchaseGenerated($成員,$包,$發票,$購買) { –

+1

它($成員,$包,$發票, $購買) { – user1658599

回答

2

所有變量都是private這意味着您無法從對象外部訪問它們。查看發票類的類定義。應該有一些功能來從對象中獲取數量,否則您可以爲課程添加這樣的功能。

這就是問題的分離。該類可能會在將來發生變化,可能不會使用相同的結構,因此您應該使用對象函數來訪問屬性,不要直接作爲變量訪問它們。

您可以在the manual或關於面向對象編程的書中閱讀關於此主題的更多信息。

+0

這是一個函數內雖然 公共職能onPurchaseGenerated內 – user1658599

+1

發票顯然是它自己的類。您不能從其他類訪問私有屬性。 –

2

似乎所有數據都在private屬性中。您無法直接從外部訪問它。

請閱讀本課程的文檔。它應該有一些你可以調用的方法,比如getQuantity(),它會爲你提供數據。這取決於課程是如何書寫的以及它應該如何使用。

相關問題