Php SimpleXML-将值捕获到单个数组中

Php SimpleXML-将值捕获到单个数组中,php,arrays,simplexml,Php,Arrays,Simplexml,我正在使用以下代码在线从XML提要获取结果 <?php $url="http://www.domain.com/xmlapi-im/years.asp"; $xmlinfo = simplexml_load_file($url); echo '<pre>'; var_dump($xmlinfo); echo '</pre>'; ?> 我试图从“year”中获取值并将其放入单个数组中,稍后我将在foreach循环中使用该数组。我不知道如何从这么远的地方获取这些

我正在使用以下代码在线从XML提要获取结果

<?php
$url="http://www.domain.com/xmlapi-im/years.asp";
$xmlinfo = simplexml_load_file($url);
echo '<pre>';
var_dump($xmlinfo);
echo '</pre>';
?>
我试图从“year”中获取值并将其放入单个数组中,稍后我将在foreach循环中使用该数组。我不知道如何从这么远的地方获取这些值,我有点困惑


非常感谢您的帮助

如果您所需要的只是年份的值,那么只需使用xpath:返回一个SimpleXML对象数组,您可以从那里使用它。在这个特殊的例子中,这就是我所需要的。虽然过一会儿,我会在查询随年份变化的品牌时需要额外的值。好的,那么你想将两者关联起来吗?还是我弄错了?嘿。我想做的是获取年份的值,但我还有其他XML提要,我正在解析,它们有不止一个值需要获取。你能发布这些其他提要的示例吗,也许你到目前为止已经尝试了什么?我希望能帮助你。
object(SimpleXMLElement)#1 (1) {
  ["table"]=>
  array(52) {
    [0]=>
    object(SimpleXMLElement)#2 (1) {
      ["year"]=>
      string(4) "2014"
    }
    [1]=>
    object(SimpleXMLElement)#3 (1) {
      ["year"]=>
      string(4) "2013"
    }
    [2]=>
    object(SimpleXMLElement)#4 (1) {
      ["year"]=>
      string(4) "2012"
    }
    [3]=>
    object(SimpleXMLElement)#5 (1) {
      ["year"]=>
      string(4) "2011"
    }
    [4]=>
    object(SimpleXMLElement)#6 (1) {
      ["year"]=>
      string(4) "2010"
    }
    [5]=>
    object(SimpleXMLElement)#7 (1) {
      ["year"]=>
      string(4) "2009"
    }
    [6]=>
    object(SimpleXMLElement)#8 (1) {
      ["year"]=>
      string(4) "2008"
    }
    [7]=>
    object(SimpleXMLElement)#9 (1) {
      ["year"]=>
      string(4) "2007"
    }
    [8]=>
    object(SimpleXMLElement)#10 (1) {
      ["year"]=>
      string(4) "2006"
    }
    [9]=>
    object(SimpleXMLElement)#11 (1) {
      ["year"]=>
      string(4) "2005"
    }
    [10]=>
    object(SimpleXMLElement)#12 (1) {
      ["year"]=>
      string(4) "2004"
    }
    [11]=>
    object(SimpleXMLElement)#13 (1) {
      ["year"]=>
      string(4) "2003"
    }
    [12]=>
    object(SimpleXMLElement)#14 (1) {
      ["year"]=>
      string(4) "2002"
    }
    [13]=>
    object(SimpleXMLElement)#15 (1) {
      ["year"]=>
      string(4) "2001"
    }
    [14]=>
    object(SimpleXMLElement)#16 (1) {
      ["year"]=>
      string(4) "2000"
    }
    [15]=>
    object(SimpleXMLElement)#17 (1) {
      ["year"]=>
      string(4) "1999"
    }
    [16]=>
    object(SimpleXMLElement)#18 (1) {
      ["year"]=>
      string(4) "1998"
    }
    [17]=>
    object(SimpleXMLElement)#19 (1) {
      ["year"]=>
      string(4) "1997"
    }
    [18]=>
    object(SimpleXMLElement)#20 (1) {
      ["year"]=>
      string(4) "1996"
    }
    [19]=>
    object(SimpleXMLElement)#21 (1) {
      ["year"]=>
      string(4) "1995"
    }
    [20]=>
    object(SimpleXMLElement)#22 (1) {
      ["year"]=>
      string(4) "1994"
    }
    [21]=>
    object(SimpleXMLElement)#23 (1) {
      ["year"]=>
      string(4) "1993"
    }
    [22]=>
    object(SimpleXMLElement)#24 (1) {
      ["year"]=>
      string(4) "1992"
    }
    [23]=>
    object(SimpleXMLElement)#25 (1) {
      ["year"]=>
      string(4) "1991"
    }
    [24]=>
    object(SimpleXMLElement)#26 (1) {
      ["year"]=>
      string(4) "1990"
    }
    [25]=>
    object(SimpleXMLElement)#27 (1) {
      ["year"]=>
      string(4) "1989"
    }
    [26]=>
    object(SimpleXMLElement)#28 (1) {
      ["year"]=>
      string(4) "1988"
    }
    [27]=>
    object(SimpleXMLElement)#29 (1) {
      ["year"]=>
      string(4) "1987"
    }
    [28]=>
    object(SimpleXMLElement)#30 (1) {
      ["year"]=>
      string(4) "1986"
    }
    [29]=>
    object(SimpleXMLElement)#31 (1) {
      ["year"]=>
      string(4) "1985"
    }
    [30]=>
    object(SimpleXMLElement)#32 (1) {
      ["year"]=>
      string(4) "1984"
    }
    [31]=>
    object(SimpleXMLElement)#33 (1) {
      ["year"]=>
      string(4) "1983"
    }
    [32]=>
    object(SimpleXMLElement)#34 (1) {
      ["year"]=>
      string(4) "1982"
    }
    [33]=>
    object(SimpleXMLElement)#35 (1) {
      ["year"]=>
      string(4) "1981"
    }
    [34]=>
    object(SimpleXMLElement)#36 (1) {
      ["year"]=>
      string(4) "1980"
    }
    [35]=>
    object(SimpleXMLElement)#37 (1) {
      ["year"]=>
      string(4) "1979"
    }
    [36]=>
    object(SimpleXMLElement)#38 (1) {
      ["year"]=>
      string(4) "1978"
    }
    [37]=>
    object(SimpleXMLElement)#39 (1) {
      ["year"]=>
      string(4) "1977"
    }
    [38]=>
    object(SimpleXMLElement)#40 (1) {
      ["year"]=>
      string(4) "1976"
    }
    [39]=>
    object(SimpleXMLElement)#41 (1) {
      ["year"]=>
      string(4) "1975"
    }
    [40]=>
    object(SimpleXMLElement)#42 (1) {

      ["year"]=>
      string(4) "1974"
    }
    [41]=>
    object(SimpleXMLElement)#43 (1) {
      ["year"]=>
      string(4) "1973"
    }
    [42]=>
    object(SimpleXMLElement)#44 (1) {
      ["year"]=>
      string(4) "1972"
    }
    [43]=>
    object(SimpleXMLElement)#45 (1) {
      ["year"]=>
      string(4) "1971"
    }
    [44]=>
    object(SimpleXMLElement)#46 (1) {
      ["year"]=>
      string(4) "1970"
    }
    [45]=>
    object(SimpleXMLElement)#47 (1) {
      ["year"]=>
      string(4) "1969"
    }
    [46]=>
    object(SimpleXMLElement)#48 (1) {
      ["year"]=>
      string(4) "1968"
    }
    [47]=>
    object(SimpleXMLElement)#49 (1) {
      ["year"]=>
      string(4) "1967"
    }
    [48]=>
    object(SimpleXMLElement)#50 (1) {
      ["year"]=>
      string(4) "1966"
    }
    [49]=>
    object(SimpleXMLElement)#51 (1) {
      ["year"]=>
      string(4) "1965"
    }
    [50]=>
    object(SimpleXMLElement)#52 (1) {
      ["year"]=>
      string(4) "1964"
    }
    [51]=>
    object(SimpleXMLElement)#53 (1) {
      ["year"]=>
      string(4) "1955"
    }
  }
}