Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Instagram API与Laravel 5.4_Php_Arrays_Laravel_Api_Instagram - Fatal编程技术网

Php Instagram API与Laravel 5.4

Php Instagram API与Laravel 5.4,php,arrays,laravel,api,instagram,Php,Arrays,Laravel,Api,Instagram,我正在使用Instagram软件包将用户数据获取到我的应用程序中 下面是我用来获得结果的代码: public function instagram() { $insta = new Instagram(); $getUser = $insta->get('gopro'); dd($getUser); } 当我转储结果时,我会在返回时获得此数组: array:20 [▼ 0 => {#205 ▼ +"id": "1552323772757218591

我正在使用Instagram软件包将用户数据获取到我的应用程序中

下面是我用来获得结果的代码:

public function instagram()
{
   $insta = new Instagram();

   $getUser = $insta->get('gopro');

   dd($getUser);
}
当我转储结果时,我会在返回时获得此数组:

array:20 [▼
  0 => {#205 ▼
    +"id": "1552323772757218591_28902942"
    +"code": "BWK9j8rlpUf"
    +"user": {#208 ▶}
    +"images": {#202 ▼
      +"thumbnail": {#203 ▶}
      +"low_resolution": {#214 ▶}
      +"standard_resolution": {#204 ▼
        +"width": 640
        +"height": 640
        +"url": "https://scontent-frt3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/19624693_104174916895493_9107740182827761664_n.jpg"
      }
    }
    +"created_time": "1499271435"
    +"caption": {#207 ▶}
    +"likes": {#215 ▶}
    +"comments": {#222 ▶}
    +"can_view_comments": true
    +"can_delete_comments": false
    +"type": "image"
    +"link": "https://www.instagram.com/p/BWK9j8rlpUf/"
    +"location": {#223 ▶}
    +"alt_media_url": null
  }
  1 => {#224 ▶}
  2 => {#251 ▶}
  3 => {#278 ▶}

]
现在,我正试图接近的是: 我想在我的laravel应用程序上集成一些图像。基本上,我想从每个数组
图像->标准分辨率->url
获取图像url

我曾尝试使用double
foreach
迭代数组,但迄今为止运气不佳


关于如何实现这一点有什么建议吗?

您好,您可能会在数组中获得结果。您可以将数组转换为集合。laravel中有一个很好的助手

   $yourCollection =  collect(yourArray);
然后,您可以对集合应用与Eloquent相同的查询,还可以应用foreach循环

编辑2

你也可以这样做

 $yourArray = json_decode($getUser,true);
您可以在其上应用循环

@foreach($yourArray as $arr){
    //do what ever you want to do with
   $arr['standard_resolution']['url'];
  }

我希望这能有所帮助。

使用laravel提供的
map
只需获取URL即可

$data = collect($getUser)->map(function($v) {
    return $v->images->standard_resolution->url;
});
您还可以使用
foreach

$urls = [];
foreach ($getUser as $row) {
    array_push($urls, $row->images->standard_resolution->url);
}

dd($urls);

请提及正在使用的软件包并显示用于迭代的代码。请尝试
$getUser->pulk(['images.standard_resolution.url'])->where('type','image')->toArray()
@user2094178我得到的结果:调用数组上的成员函数pulk()
collect([$getUser])->pulk(['images.standard_resolution.url'])->where('‌​键入“,”image“->toArray()
@user2094178返回时我得到一个空数组[]是,使用。并使用json_解码返回到对象或数组