PHP从对象访问数据

PHP从对象访问数据,php,Php,我填充一个数组,当我输出以下内容时 var_dump($users["JohnDoe"]); adLDAPUserCollection {#348 ▼ #adldap: adLDAP {#287 ▶} #currentObject: null #info: array:2 [▼ "count" => 1 0 => array:17 [▼ "telephonenumber" => array:2 [▼ "count" =&

我填充一个数组,当我输出以下内容时

var_dump($users["JohnDoe"]);
adLDAPUserCollection {#348 ▼
  #adldap: adLDAP {#287 ▶}
  #currentObject: null
  #info: array:2 [▼
    "count" => 1
    0 => array:17 [▼
      "telephonenumber" => array:2 [▼
        "count" => 1
        0 => "123456789"
      ]
      0 => "telephonenumber"
      "displayname" => array:2 [▼
        "count" => 1
        0 => "John Doe"
      ]
      1 => "displayname"
      "department" => array:2 [▼
        "count" => 1
        0 => "Some Department"
      ]
      2 => "department"
      "primarygroupid" => array:2 [▼
        "count" => 1
        0 => "123"
      ]
      3 => "primarygroupid"
      "objectsid" => array:2 [▼
        "count" => 1
        0 => b"\x01\x05\x00\x00\x00\x00\x00\x05\x"
      ]
      4 => "objectsid"
      "samaccountname" => array:2 [▼
        "count" => 1
        0 => "JohnDoe"
      ]
      5 => "samaccountname"
      "mail" => array:2 [▼
        "count" => 1
        0 => "JohnDoe@email.com"
      ]
    ]
  ]
}
var_dump($users["JohnDoe"]->info[0]["department"][0]);
我看到了如下情况

var_dump($users["JohnDoe"]);
adLDAPUserCollection {#348 ▼
  #adldap: adLDAP {#287 ▶}
  #currentObject: null
  #info: array:2 [▼
    "count" => 1
    0 => array:17 [▼
      "telephonenumber" => array:2 [▼
        "count" => 1
        0 => "123456789"
      ]
      0 => "telephonenumber"
      "displayname" => array:2 [▼
        "count" => 1
        0 => "John Doe"
      ]
      1 => "displayname"
      "department" => array:2 [▼
        "count" => 1
        0 => "Some Department"
      ]
      2 => "department"
      "primarygroupid" => array:2 [▼
        "count" => 1
        0 => "123"
      ]
      3 => "primarygroupid"
      "objectsid" => array:2 [▼
        "count" => 1
        0 => b"\x01\x05\x00\x00\x00\x00\x00\x05\x"
      ]
      4 => "objectsid"
      "samaccountname" => array:2 [▼
        "count" => 1
        0 => "JohnDoe"
      ]
      5 => "samaccountname"
      "mail" => array:2 [▼
        "count" => 1
        0 => "JohnDoe@email.com"
      ]
    ]
  ]
}
var_dump($users["JohnDoe"]->info[0]["department"][0]);
现在我要做的是获取用户的部门。当我尝试以下方法时

var_dump($users["JohnDoe"]);
adLDAPUserCollection {#348 ▼
  #adldap: adLDAP {#287 ▶}
  #currentObject: null
  #info: array:2 [▼
    "count" => 1
    0 => array:17 [▼
      "telephonenumber" => array:2 [▼
        "count" => 1
        0 => "123456789"
      ]
      0 => "telephonenumber"
      "displayname" => array:2 [▼
        "count" => 1
        0 => "John Doe"
      ]
      1 => "displayname"
      "department" => array:2 [▼
        "count" => 1
        0 => "Some Department"
      ]
      2 => "department"
      "primarygroupid" => array:2 [▼
        "count" => 1
        0 => "123"
      ]
      3 => "primarygroupid"
      "objectsid" => array:2 [▼
        "count" => 1
        0 => b"\x01\x05\x00\x00\x00\x00\x00\x05\x"
      ]
      4 => "objectsid"
      "samaccountname" => array:2 [▼
        "count" => 1
        0 => "JohnDoe"
      ]
      5 => "samaccountname"
      "mail" => array:2 [▼
        "count" => 1
        0 => "JohnDoe@email.com"
      ]
    ]
  ]
}
var_dump($users["JohnDoe"]->info[0]["department"][0]);
我返回空值。我怎样才能得到这个用户部门


谢谢

您能添加原始json对象吗?确切地说,
$users
?一系列的实例?我想是的-最初它来自于此,然后我猜它只是
$users['JohnDoe']['telephonenumber']
。如果这不起作用,请使用
var\u导出($users['JohnDoe'])
(而不是虚构的var\u转储)的输出。