doushan6692 2015-12-07 06:26
浏览 266

如何从多维数组中仅获取数组值

I am doing project in laravel. I am fetching a value from database in user1 variable.

foreach($users1 as $us){
                    $uss[$i] = $us->city_id;
                    $users2[$i] = DB::table('provider_city')->select('provider_id')->where('city_id','=', $uss[$i])->get();
                    $i++;
                }
return $users2;

when I return user2, I am getting [[{"provider_id":"14785"}],[{"provider_id":"125478"}]] such values.

I want only values like ['14785','125478'].

I know this may be very simple. Give suggestions.

  • 写回答

3条回答 默认 最新

  • dongxin0031 2015-12-07 06:30
    关注

    This can be achieved with json_decode, like so

    $json= '[
        {
          "provider_id": "14785"
        },
        { 
          "provider_id": "125478"
        }
      ]';
    
    $jsonDecoded = json_decode($json);
    foreach($jsonDecoded as $item)
    {
        //Do something with it, e.g
        echo $item->provider_id;
    }
    

    Edit: Upon finding out that this is a multidimensional array

    This question here should point you in the right direction.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?