我想通過這個數據對象在我的視圖中循環。但是,我收到以下錯誤:Trying to get property of non-object
。這是我第一次遇到渲染數組/對象的問題......也許這僅僅是星期日的情況......但是我不能得到這個輸出結果foreach
。幫幫我? 編輯:我將鍵/值「search_type」添加到返回的數組 - 我認爲這可能會導致問題?PHP - Foreach對象
$results = $twitter->get("users/search", ["q" => $term, "count" => $num, "include_entities" => 'false']);
$results['search_type'] = 'people';
回報:
{
"0": {
"id": 1108217089,
"id_str": "1108217089",
"name": "Marketing",
"screen_name": "SocialMedia246",
"location": "Canada",
"description": "Marketing|PR|Brand Consultant.Lover of Music|Fashion & life.A dynamic young entrepreneur with an unconventional out of the box approach to marketing & business.",
},
"1": {
...
},
search_type: "people"
的foreach:
@foreach ($search_results as $result => $profile)
<div class="large-3 columns">
{{ $profile->id }}
</div>
@endforeach
最小化vardump,爲search_results:
array:21 [▼
0 => {#433 ▶}
1 => {#435 ▶}
2 => {#449 ▶}
3 => {#455 ▶}
4 => {#461 ▶}
5 => {#468 ▶}
6 => {#472 ▶}
7 => {#479 ▶}
8 => {#492 ▶}
9 => {#505 ▶}
10 => {#513 ▶}
11 => {#526 ▶}
12 => {#531 ▶}
13 => {#538 ▶}
14 => {#542 ▶}
15 => {#548 ▶}
16 => {#555 ▶}
17 => {#560 ▶}
18 => {#564 ▶}
19 => {#577 ▶}
"search_type" => "people"
]
你可以做$ search_results一個的var_dump並保證其的對象,而不是原始JSON字符串? –
剛剛做過 - 這是一個數組 –
將'$ profile-> id'更改爲'$ profile ['id']' –