从xml中读取数据并创建一个数组对象


reading data from xml and create an array object

我是php的新手,我正在使用metro-websign创建我的网站。有一个插件占用了一个数组。以下代码运行良好:

<? php
$photoNewsPath = array(
  "photo/committees/spirit-rock/20150203-anna.jpg",
  "photo/news/20150207 - 100 day.jpg"
);
$photoNewsTitle = array("Post your photos on the website", "100 school day = pajama day fun");
var_dump($photoNewsPath);
$tile[] = array(
  "type" => "slideshow",
  "images" => $photoNewsPath,
  "classes" => "");

但是当我从xml文件读取数组时:

<? php
$photonews = simplexml_load_file("config'photonews.xml") or die("Error: Cannot create object");
foreach($photonews - > news as $news) {
  $photoNewsPath[] = (string) $news - > path;
}
var_dump($photoNewsPath);
$tile[] = array(
  "type" => "slideshow",
  "images" => $photoNewsPath,
  "classes" => ""); ?>

这个插件已经不起作用了。我使用var_dump从两个代码段中转储数组。结果完全相同。是什么让数组不同,从而导致php插件失败?

有线索吗?

foreach中有一个错误。这是在将<path></path>标记转换为xml

<?php
$photonews = simplexml_load_file("config/photonews.xml") or die("Error: Cannot create object");
$photoNewsPath=array();
foreach($photonews as $key => $value) {
$photoNewsPath[]= (string) $photonews->path;
}
// var_dump($photoNewsPath);
$tile[] = array(
  "type" => "slideshow",
  "images" => $photoNewsPath,
  "classes" => ""); ?>