我有一个集合
Illuminate\Support\Collection Object ( [items:protected] =>
Array ( [0] => Array ( [url] => / [pageTitle] => Something [pageViews] => 66 ) ) )
如何从此集合中获取pageTitle和pageView?
答案 0 :(得分:0)
您需要先选择集合的第一条记录,然后才能访问其属性。
$my_collection = $my_collection->first();
//then you can do
$my_collection->pageTitle;
//or
$my_collection->pageViews;
如果它为您提供can not read property of non-object
,则将属性作为数组
$my_collection = $my_collection->first();
//then you can do
$my_collection['pageTitle'];
//or
$my_collection['pageViews'];
答案 1 :(得分:0)
感谢您的帮助,但我解决了。
foreach($my_collection as $key){ $key['pageTitle']}