我有以下数组数据
array:1 [▼
"data" => array:1 [▼
"collections" => array:1 [▼
"edges" => array:58 [▼
0 => array:1 [▼
"node" => array:3 [▼
"id" => "1"
"title" => "Company"
"image" => array:1 [▼
"src" => "myimage.png"
]
]
]
1 => array:1 [▼
"node" => array:3 [▼
"id" => "2"
"title" => "Popcorn"
"image" => array:1 [▼
"src" => "myimage.png"
]
]
]
]
]当我尝试使用下面的代码进行循环时
@foreach ($shopify as $item)
@foreach ($item['collections'] as $key => $data)
<pre>
@php
print_r($data);exit();
@endphp
</pre>
@endforeach
@endforeach我得到了下面的数据
Array
(
[0] => Array
(
[node] => Array
(
[id] => 1
[title] => Company
[image] => Array
(
[src] => 'myimage.png'
)
)
)
[1] => Array
(
[node] => Array
(
[id] => 2
[title] => Popcorn
[image] => Array
(
[src] => 'myimage.png'
)
)
)我的问题是我不能在数组中获取id、title等。当我尝试循环时,它给出了undefined index问题?
你知道如何获得id、title以及image(src)吗?
我使用graphql api从shopify获得了收集数据,并尝试集成到laravel中
发布于 2020-10-12 23:16:36
我想你可以将你的代码简化为:
@foreach ($shopify['data']['collections']['edges'] as $edge)
{{ $edge['node']['id'] }} - {{ $edge['node']['title'] }}
<img src="{{ $edge['node']['image']['src'] }}">
@endforeachhttps://stackoverflow.com/questions/64320467
复制相似问题