-1

我想从这个数组中检索数量。

  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->quantity、$invoice[1]->quantity、$this->$invoice->quantity,但它们似乎都没有显示。

它仍然根本不显示,我试图 print_r 那就是它给我的数组。

4

2 回答 2

3

所有变量都private意味着您无法从对象外部访问它们。查看发票类的类定义。应该有一些函数可以从对象中获取数量,否则您可以将这样的功能添加到类中。

重点是关注点分离。该类将来可能会发生变化并且可能不会使用相同的结构,因此您应该使用对象函数来访问属性,不要直接将它们作为变量访问。

您可以在手册或有关面向对象编程的书籍中阅读有关此主题的更多信息。

于 2012-09-09T19:16:45.397 回答
2

似乎所有数据都在一个private属性中。您不能直接从外部访问它。

阅读该课程的文档。它应该有一些你可以调用的方法,比如getQuantity(),它会为你获取数据。这取决于类是如何编写的以及它应该如何使用。

于 2012-09-09T19:17:00.533 回答