如何访问受保护的数组值?
how to access protected array values ?
您好,我有这个数组,但我不确定如何从中获取名称、品牌、图像、标记值?
Gloudemans\Shoppingcart\CartCollection Object
(
[items:protected] => Array
(
[1264477c2182cc04a63fde1186741fa7] => Gloudemans\Shoppingcart\CartRowCollection Object
(
[associatedModel:protected] =>
[associatedModelNamespace:protected] =>
[items:protected] => Array
(
[rowid] => 1264477c2182cc04a63fde1186741fa7
[id] => 1
[name] => washington apples
[qty] => 1
[price] => 90
[options] => Gloudemans\Shoppingcart\CartRowOptionsCollection Object
(
[items:protected] => Array
(
[brand] => awesome apple
[image] => C:\xampp\htdocs\srsgrocery\storage/app/products/1/apple-06.jpg
[token] => WiQgUjqgHEB3HZ2ImJ6iPQWHnm246twFD3Uyk6AH
)
)
[subtotal] => 90
)
)
)
)
我正在使用名为 laravel 的 php 框架。
请帮忙。
将对象保存在变量中并执行foreach
循环,
foreach($cart as $item) {
echo $item->name;
echo $item->options->brand;
}
如果这不起作用,您可以使用 collection
class.
中的 fetch
方法
http://laravel.com/api/5.0/Illuminate/Support/Collection.html#method_fetch
$item->fetch('name');
并且您正在使用的包有替代方法 search
$item->search('name');
$item->search(['options' => 'name'])
您好,我有这个数组,但我不确定如何从中获取名称、品牌、图像、标记值?
Gloudemans\Shoppingcart\CartCollection Object
(
[items:protected] => Array
(
[1264477c2182cc04a63fde1186741fa7] => Gloudemans\Shoppingcart\CartRowCollection Object
(
[associatedModel:protected] =>
[associatedModelNamespace:protected] =>
[items:protected] => Array
(
[rowid] => 1264477c2182cc04a63fde1186741fa7
[id] => 1
[name] => washington apples
[qty] => 1
[price] => 90
[options] => Gloudemans\Shoppingcart\CartRowOptionsCollection Object
(
[items:protected] => Array
(
[brand] => awesome apple
[image] => C:\xampp\htdocs\srsgrocery\storage/app/products/1/apple-06.jpg
[token] => WiQgUjqgHEB3HZ2ImJ6iPQWHnm246twFD3Uyk6AH
)
)
[subtotal] => 90
)
)
)
)
我正在使用名为 laravel 的 php 框架。
请帮忙。
将对象保存在变量中并执行foreach
循环,
foreach($cart as $item) {
echo $item->name;
echo $item->options->brand;
}
如果这不起作用,您可以使用 collection
class.
fetch
方法
http://laravel.com/api/5.0/Illuminate/Support/Collection.html#method_fetch
$item->fetch('name');
并且您正在使用的包有替代方法 search
$item->search('name');
$item->search(['options' => 'name'])