foreach语句错误

发布于 2024-11-19 07:02:22 字数 821 浏览 0 评论 0原文

谁能告诉我这段代码有什么问题吗?

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-11-26 07:02:22

我在这里猜测是因为问题不太清楚,但我认为您需要将最后一个 foreach 中变量的顺序从

foreach ($array as $oddsArray)
{
echo $array['odds'];
echo $array['oddsID'];
}

To反转

foreach ($oddsArray as $array)
{
echo $array['odds'];
echo $array['oddsID'];
}

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'];
}
许一世地老天荒 2024-11-26 07:02:22
foreach ($array as $oddsArray)

我认为你有这个倒退......

为了避免混淆,我总是使用一些容易记住的东西......

foreach ($oddsArray as $key => $value) {

或者

foreach ($oddsArray as $value) {

甚至......

然后你永远不会混淆(希望永远不会:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文