dtye7921 2014-08-01 12:27
浏览 132
已采纳

如何在PHP中访问stdClass对象的元素

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?

  • 写回答

3条回答 默认 最新

  • douou0977 2014-08-01 12:30
    关注
    $objectVar = $modas_pares[0]->pares; //spits out 4
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?