Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP关联数组特定值。_Php_Arrays_Associative - Fatal编程技术网

PHP关联数组特定值。

PHP关联数组特定值。,php,arrays,associative,Php,Arrays,Associative,我一直想弄明白这一点已经有一段时间了。如果您有任何建议,我们将不胜感激。我只需要访问[“项”]的数组。我如何获得访问权限 array(1) { [0]=> object(SimpleXMLElement)#16 (2) { ["@attributes"]=> array(2) { ["Name"]=> string(10) "AuthorList" ["Type"]=> string(4) "List

我一直想弄明白这一点已经有一段时间了。如果您有任何建议,我们将不胜感激。我只需要访问[“项”]的数组。我如何获得访问权限

array(1) {
  [0]=>
  object(SimpleXMLElement)#16 (2) {
    ["@attributes"]=>
    array(2) {
      ["Name"]=>
      string(10) "AuthorList"
      ["Type"]=>
      string(4) "List"
    }
    ["Item"]=>
    array(3) {
      [0]=>
      string(9) "Smith, Joe"
      [1]=>
      string(10) "Peter, Ann"
      [2]=>
      string(18) "Magoo, Mr"
    }
  }
}

假设此结构位于名为
var1
的变量中,您应该能够使用以下方法访问

$var1[0]->Item // returns the array
我试着解释一下

如您所见,第一个数组索引是一个对象。 如果在var_转储中看到类似的内容,则可以通过延迟对象来访问它

这与创建对象和访问公共变量是一样的:

$var1 = new Object();
// when your Object variables are public so you could access them by deference the Object

echo $var1->myVariable; // will echo the public variable "myVariable" 

因此,亚当的答案是正确的:)

你能提供比看起来像一个var_垃圾场更多的信息吗?谢谢你们的回答。我真的让事情复杂化了。在这个项目上工作了太多个小时后,我的头脑变得一团糟。