I am having some trouble displaying XML values stored in my arrays. I successfully traversed the nodes, but I'm trying to echo the arrays all together. Here is my code:
<?php
$other_feed_url = "http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=NFL";
$xml2 = simplexml_load_file($other_feed_url);
$AwayLine[] = (string)$xml2->spread_visiting;
$HomeLine[] = (string)$xml2->home_visiting;
$AwayMoneyLine[] = (string)$xml2->moneyline_visiting;
$HomeMoneyLine[] = (string)$xml2->moneyline_home;
$AwaySpreadAdjust[] = (string)$xml2->spread_adjust_visiting;
$HomeSpreadAdjust[] = (string)$xml2->spread_adjust_home;
$UnderAdjust[] = (string)$xml2->under_adjust;
$OverAdjust[] = (string)$xml2->over_adjust;
$TotalPoints[] = (string)$xml2->total_points;
for($i=0;$i<20; $i++) {
foreach ($xml2->events->event as $event) {
$Spread = $event->periods->period[0]->spread;
$MoneyLine = $event->periods->period[0]->moneyline;
$TotalPoints = $event->periods->period[0]->total;
$AwayLine[] = $Spread->spread_visiting;
$HomeLine[] = $Spread->spread_home;
$AwayMoneyLine[] = $MoneyLine->moneyline_visiting;
$HomeMoneyLine[] = $MoneyLine->moneyline_home;
$UnderAdjust[] = $TotalPoints->under_adjust;
$OverAdjust[] = $TotalPoints->over_adjust;
$TotalPoints[] = $TotalPoints->total_points;
}
echo '<br>';
echo $AwayLine[$i];
echo '<br>';
echo $HomeLine[$i];
echo '<br>';
echo $AwayMoneyLine[$i];
echo '<br>';
echo $HomeMoneyLine[$i];
echo '<br>';
echo $TotalPoints[$i];
}
?>
$AwayLineand the$HomeLinearrays are printed. For resulting output, I have one goal which is to be able to display all of the variables at the end. I did have nested foreach loops with $Spread,$MoneyLine and $TotalPoints, but I was still unable to print anything but $AwayLine and $HomeLine.$AwayMoneyLineand so on contain? Maybe they are just empty nodes. Try usingvar_dump($AwayMoneyLine)to see what they contain, or check the generated source for your script.var_dump($AwayMoneyLine);did result in NULL values, which is what I was expecting. After taking out this code$Spread = $event->periods->period[0]->spread;the resulting code was blank, so the error must deal with $AwayMoneyLine. Any suggestions? Thanks.$event->periods->period[0]->moneylinedoesn't exist, see my answer below.