如何访问受保护的数组值? [英] how to access protected array values ?
本文介绍了如何访问受保护的数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数组,我不确定如何从中获取名称,品牌,图像,令牌值?
Hi I have this array and I am not sure how will I fetch the name , brand, image, token values from it?
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框架.
请帮忙.
I am using the php framework called laravel.
Please help.
推荐答案
将对象保存在变量中并执行foreach
循环,
save the object in a variable and do a foreach
loop,
foreach($cart as $item) {
echo $item->name;
echo $item->options->brand;
}
如果这不起作用,则可以使用collection
类中的fetch
方法.
if that's not working, you can use the fetch
method from the collection
class.
http://laravel.com/api/5.0/Illuminate/Support/Collection.html#method_fetch
$item->fetch('name');
,并且您使用的软件包具有替代方法search
and the package you're using has a alternate method search
$item->search('name');
$item->search(['options' => 'name'])
这篇关于如何访问受保护的数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文