doujiang1913 2018-04-09 12:13
浏览 110
已采纳

Laravel - 数组获取属性

I'm working on something which requires me to get an attribute from an array, Which I thought was fairly simple. Weirdly I can't figure out how to get the attribute. The attributes that I need to achieve is the IP address in an array. If I dumpDie the object it returns the following

0 => Networks{#1010 ▼
  +ipAddress: "192.125.3.232"
  +gateway: "192.125.0.1"
  +type: "public"
  etc......

Now I need to receive the IP address from this array. How can I achieve that?

I've tried doing things like

$data['networks'][0]['ipAddress']; or $data->{'networks[0]'}->{'ipAddress'}

But both of them gave the error

Cannot use object of type DigitalOceanV2\Entity\Droplet as array

What is the solution to this problem?

EDIT

I get the object doing this

$droplet = DigitalOcean::droplet()->create($storeName, 'ams3', 's-1vcpu-1gb', $images[0]->id);

$data = DigitalOcean::droplet()->getById($droplet->id);
  • 写回答

2条回答 默认 最新

  • dou1908 2018-04-09 13:11
    关注

    But both of them gave the error

    Cannot use object of type DigitalOceanV2\Entity\Droplet as array

    Because Droplet is an object, so you need to use -> to get the properties.

    $data->networks[0]->ipAddress

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测