Php 多维数组-访问结构中的项

Php 多维数组-访问结构中的项,php,foreach,Php,Foreach,如何在以下结构中访问“类型”项 以下是foreach在变量$item中的输出(输出自print\r($item);) 根据PHP的版本,并假设对象具有适当的getter,您可以执行以下操作: $item->getCore()->cart->getItems()[3]->getItemOptions()['type']; 如果它们没有getter,您只能从相应的类内部访问Cartthrob\u item\u product::core、Cartthrob\u cart::

如何在以下结构中访问“类型”项

以下是foreach在变量$item中的输出(输出自
print\r($item);


根据PHP的版本,并假设对象具有适当的getter,您可以执行以下操作:

$item->getCore()->cart->getItems()[3]->getItemOptions()['type'];
如果它们没有getter,您只能从相应的类内部访问
Cartthrob\u item\u product::core
Cartthrob\u cart::items
、和
Cartthrob\u item\u product::item\u选项
,因为它们受到
保护

另一种可能性是,索引3中的
carthrob\u item\u产品
与$item是同一个对象。在这种情况下,假设对象具有适当的getter,您只需执行以下操作:

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

$arr->core->cart->items[3]->item_选项['type']
$item->getItemOptions()['type'];