2016-12-29 38 views
0

如何访问以下结构中的“类型”项目?多维阵列 - 访问结构中的物品

下面是一个foreach输出,在变量$项目(从print_r($item);输出)

Cartthrob_item_product Object ( 
    [core:protected] => Cartthrob_core_ee Object ( 
     [cart] => Cartthrob_cart Object ( 
      [items:protected] => Array ( 
       [3] => Cartthrob_item_product Object ( 
        [item_options:protected] => Array ( 
         [type] => product 
        ) 
       ) 
      ) 
     ) 
    ) 
) 
+1

'$ arr->核心 - > cart->项目[3] - > item_options [ '型']' –

回答

0

根据PHP的版本,并假设对象有相应的getter方法,你可以这样做:

$item->getCore()->cart->getItems()[3]->getItemOptions()['type']; 

如果他们没有干将,你只能访问Cartthrob_item_product::coreCartthrob_cart::items,并从各自的班级里面自己Cartthrob_item_product::item_options,因为他们是protected

另一种可能性是索引3处的Cartthrob_item_product与$ item是同一个对象。在这种情况下,假定对象具有适当的获取,你只需要做:

$item->getItemOptions()['type'];