foreach语句错误
谁能告诉我这段代码有什么问题吗?
<?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'];
}
?>
我收到的错误是:
警告:在线 /home/pokerint/public_html/test.php 中为 foreach() 提供的参数无效
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这里猜测是因为问题不太清楚,但我认为您需要将最后一个 foreach 中变量的顺序从
To反转
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
To
我认为你有这个倒退......
为了避免混淆,我总是使用一些容易记住的东西......
或者
甚至......
然后你永远不会混淆(希望永远不会:)
I think you have this backwards ...
To avoid confusion , I always use something easy to remember ...
OR
even ...
then you will never get mixed up (well hopefully never :)