如何访问PHP stdClass的对象的元素 [英] How to access elements of stdClass Object in PHP
问题描述
我曾尝试其他职位的解释我不能让它的工作,因为我总是得到以下警告:警告:get_object_vars()预计参数1是对象,数组中...给出
该stdClass的对象数组是这样的:
阵列
(
[0] => stdClass的对象
(
[削去] => 4
[MODA] => 9
) [1] => stdClass的对象
(
[削去] => 3
[MODA] => 8
) [2] => stdClass的对象
(
[削去] => 2
[MODA] => 8
) [3] => stdClass的对象
(
[削去] =>五
[MODA] => 4
) [4] => stdClass的对象
(
[削去] => 1
[MODA] => 1
) [5] => stdClass的对象
(
[削去] => 6
[MODA] => 1
))
和我尝试访问值 - MODAS和削去他们的人数分别为 - 例如,它是第一个元素削去,其值4使用,例如:
回声get_object_vars($ modas_pares)[0] ['削去'];
但我得到以下警告:
警告:get_object_vars()预计参数1是对象,数组
在给定的
块引用>那我怎么才能访问这些值?
解决方案$ objectVar = $ modas_pares [0] - >削去; //吐出4
i have tried the other posts' explanations i can't get it to work since i always get the following warning: Warning: get_object_vars() expects parameter 1 to be object, array given in ...
The stdclass object array looks like this:
Array ( [0] => stdClass Object ( [pares] => 4 [moda] => 9 ) [1] => stdClass Object ( [pares] => 3 [moda] => 8 ) [2] => stdClass Object ( [pares] => 2 [moda] => 8 ) [3] => stdClass Object ( [pares] => 5 [moda] => 4 ) [4] => stdClass Object ( [pares] => 1 [moda] => 1 ) [5] => stdClass Object ( [pares] => 6 [moda] => 1 ) )
And i try to access the values - modas and pares and their numbers respectively - for example, the very first element which is "pares" and its value "4" by using, for example
echo get_object_vars($modas_pares)['0']['pares'];
but i get the following warning:
Warning: get_object_vars() expects parameter 1 to be object, array given in
Then how can i access these values?
解决方案$objectVar = $modas_pares[0]->pares; //spits out 4
这篇关于如何访问PHP stdClass的对象的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!