[英]php reading value from an array
I have an array and I am trying to access the value for message. 我有一个数组,我试图访问该消息的值。 I think it is throwing me off because it is an array of objects within an object. 我认为它使我失望,因为它是对象中的对象数组。 Below is what I have tried and the data structure. 以下是我尝试过的内容和数据结构。
Code: 码:
foreach ($result as $value) {
echo "$value[0]->message";
}
Array: 阵:
stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[message] => 12345
[unit] => test
[createdAt] => 2013-01-21T14:57:26.613Z
[updatedAt] => 2013-01-21T14:57:26.613Z
[objectId] => 0uiYuJcRYY
)
)
)
Remove quotes 删除引号
foreach ($result as $value) {
echo $value[0]->message;
}
There are two pobable mistakes. 有两个可能的错误。
1 - Probable the variable are $results and not $result 2 - If you are using foreach, you don't need the [0], because this is the variable $value now. 1-变量可能是$ results而不是$ result 2-如果使用的是foreach,则不需要[0],因为这是变量$ value。
try 尝试
foreach ($results as $value) {
echo $value->message;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.