I am new to php, I am using metro-websign for creating my website. There is a plugin taking an array. The following code works fine:
<? 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" => "");
But when I read the array from an xml file:
<? 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" => ""); ?>
the plugin doesn't work anymore. I use var_dump to dump the array from both code snippets. The results are identical. What could make the arrays different so the php plugin fails?
Any clues?
</div>
you have an error into foreach. this is the correct code to access at the <path></path>
tag into 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" => ""); ?>