Can anyone tell me whats wrong with this code?
<?php
$feedID = '28241415';
$oddsArray = array();
$source = file_get_contents("https://www.bwin.com/partner/xml/query.aspx?source=events&lid=1&xpath=/ROOT/EVENTS/E[@LID=46%20and%20@RID=14%20and%20@SID=4]");
$xml = simplexml_load_string($source);
$game = $xml->xpath("//G");
foreach ($game as $event)
{
if ($event['DBID'] == $feedID)
{
foreach ($event->children() as $odds)
{
开发者_运维知识库 array_push($oddsArray, array('oddsID' => $odds['DBID'], 'odds' => $odds['O']));
}
}
}
foreach ($array as $oddsArray)
{
echo $array['odds'];
echo $array['oddsID'];
}
?>
The error I am receiving is:
Warning: Invalid argument supplied for foreach() in /home/pokerint/public_html/test.php on line
I am guessing here as the question isn't quite clear but I think you need to reverse the order of your variables in your last foreach from
foreach ($array as $oddsArray)
{
echo $array['odds'];
echo $array['oddsID'];
}
To
foreach ($oddsArray as $array)
{
echo $array['odds'];
echo $array['oddsID'];
}
foreach ($array as $oddsArray)
I think you have this backwards ...
To avoid confusion , I always use something easy to remember ...
foreach ($oddsArray as $key => $value) {
OR
foreach ($oddsArray as $value) {
even ...
then you will never get mixed up (well hopefully never :)
精彩评论