简体   繁体   English

获取数组内部的数据ArrayObject

[英]Get Data ArrayObject inside array

MONTHLY_PAYMENT: "9.7",
MAINTAINANCE_FEE: "20000",
areapoints: [
{
station: "大塚",
bus: null,
walking_distance: null
},
{
station: null,
bus: null,
walking_distance: null
},
{
station: null,
bus: null,
walking_distance: null
}
]

Getting the monthly payment and maintenance fee is easy, I just use $room->MONTHLY_PAYMENT . 获得每月的付款和维护费用很容易,我只需使用$room->MONTHLY_PAYMENT

But there is an arrayobject inside of the array which I am getting an error when I use $room->areapoints[0]->bus 但是在数组内部有一个arrayobject,当我使用$room->areapoints[0]->bus时遇到错误

This is the error: 这是错误:

Undefined property: ArrayObject::$bus

What am I doing wrong here 我在这里做错了什么

Your property of $room->areapoints[0]->bus is null in your list syntax. $room->areapoints[0]->bus属性在列表语法中为null Therefore, that property doesn't exist. 因此,该属性不存在。

You need to check if it exists before using it with: 您需要先检查它是否存在,然后将其用于:

if (isset($room->areapoints[0]->bus)) {
    // ... CODE HERE ...
}

$room->areapoints[0]->bus更改$room->areapoints[0]->bus $room->areapoints[0]['bus']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM