【问题标题】:Access an array value within an object in PHP在 PHP 中访问对象内的数组值
【发布时间】:2013-04-04 23:58:50
【问题描述】:

我是 PHP 新手,正在尝试从以下访问“contactId”的值:

object(stdClass)#2 (4) { 
    ["contacts"]=> array(1) { 
        [0]=> object(stdClass)#3 (18) { 

            ["email"]=> string(24) "joewilliams@icontact.com" 
            ["firstName"]=> string(3) "Joe" 
            ["lastName"]=> string(8) "Williams" 
            ["prefix"]=> string(3) "Mr." 
            ["suffix"]=> string(3) "Jr." 
            ["fax"]=> string(0) "" 
            ["phone"]=> string(10) "8668039462" 
            ["street"]=> string(21) "2365 Meridian Parkway" 
            ["street2"]=> string(0) "" 
            ["city"]=> string(6) "Durham" 
            ["state"]=> string(2) "NC" 
            ["postalCode"]=> string(5) "27713" 
            ["createDate"]=> string(19) "2013-03-30 21:22:28" 
            ["status"]=> string(6) "normal" 
            ["bounceCount"]=> NULL 
            ["contactId"]=> string(8) "67295434" 
        } 
    } 
    ["limit"]=> int(20) 
    ["offset"]=> int(0) 
    ["total"]=> int(1) 
} 

如何获取contactId的值?

非常感谢!

【问题讨论】:

    标签: php arrays object


    【解决方案1】:

    这些不是数组,而是一个包含一个包含对象的数组的对象。 PHP对象访问语法是->

    $variableName->contacts[0]->contactId
    

    【讨论】:

    • 知道了 - 现在我知道发生了什么......呃。感谢您的快速帮助。太棒了。
    猜你喜欢
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 2014-10-17
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多