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 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?