【问题标题】:Access a nested element in php array [duplicate]访问php数组中的嵌套元素[重复]
【发布时间】:2019-03-07 17:42:26
【问题描述】:

我有一个带有这个结果的 print_r 的 PHP 对象

 fieldData: {},
portalData: {
    SubCategories: {
        0: {},
        1: {
            recordId: "3",
            SubCategories::SubCategoryName: "Multi-Channel",
            modId: "0"
    },
        2: {},
        3: {}
    }
},
recordId: "2",
modId: "3"

如何访问 SubCategoryName?

【问题讨论】:

  • 结构和值从何而来?感觉更好的方法是在填充对象时以不同的方式创建对象。
  • 感谢您快速回复我正在尝试访问此内容:SubCategories::SubCategoryName: "Multi-Channel",
  • 我可以使用以下方法访问其他变量:SubCategories->recordId;例如
  • 您应该可以使用以下方式访问它:$object->portalData->SubCategories->{1}->{'SubCategories::SubCategoryName'}
  • Magnus 我可以吻你,非常感谢

标签: php arrays object for-loop


【解决方案1】:

您应该可以使用以下方式访问它:

$object->portalData->SubCategories->{1}->{'SubCategories::SubCategoryName'} 

– Magnus Eriksson 2 分钟前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多