php如何创建foreach循环?

发布于 2024-11-06 05:15:12 字数 564 浏览 0 评论 0原文

Array
(
[0] => Array
    (
        [id] => 
        [test] => 145198
        [defender] => 5590478
        [stake] => 107
        [game_id] => 
    )

[1] => Array
    (
        [id] => 
        [test] => 145198
        [defender] => 5590478
        [stake] => 107
        [game_id] => 
    )

如何为其执行 foreach 循环?

到目前为止我已经:

 $mresults = $game_set->get_it();
foreach ($mresults as $key => $row)
{ ...dosomething}

但我相信我需要在这个里面做另一件事。

有什么想法吗? 谢谢

Array
(
[0] => Array
    (
        [id] => 
        [test] => 145198
        [defender] => 5590478
        [stake] => 107
        [game_id] => 
    )

[1] => Array
    (
        [id] => 
        [test] => 145198
        [defender] => 5590478
        [stake] => 107
        [game_id] => 
    )

how to do a foreach loop for it?

so far i have:

 $mresults = $game_set->get_it();
foreach ($mresults as $key => $row)
{ ...dosomething}

but i believe i need to do another one inside this one.

any ideas?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

何止钟意 2024-11-13 05:15:12

你的 foreach 将嵌套数组分配给 $row 变量,并且可以像这样访问:

$row["test"]
$row["id"]

如果你想再次循环,你可以这样做:

$mresults = $game_set->get_it();
foreach ($mresults as $key => $row)
{
    foreach($row as $k => $v)
    {
        echo $k." = ".$v;
    }

}

Your foreach assigns the nested array to the $row variable and can be accessed like:

$row["test"]
$row["id"]

If you wish to loop again, you can do:

$mresults = $game_set->get_it();
foreach ($mresults as $key => $row)
{
    foreach($row as $k => $v)
    {
        echo $k." = ".$v;
    }

}
凹づ凸ル 2024-11-13 05:15:12

不知道你想做什么,但尝试一下:

$mresults = $game_set->get_it();
foreach ($mresults as $key => $row) {
     echo "key: $key, row: $row\n";
}

看看它是如何工作的。

Don't know what you want to do, but try:

$mresults = $game_set->get_it();
foreach ($mresults as $key => $row) {
     echo "key: $key, row: $row\n";
}

To see how it works.

清醇 2024-11-13 05:15:12

在您的情况下, $row 将包含该内部数组,因此您可以使用 $row['test']$row['defender' 输出这些值]

In your case, $row will contain that inner array, so you can output those values using $row['test'], $row['defender'], etc.

把人绕傻吧 2024-11-13 05:15:12

这很可能就是您所需要的:

foreach ($game_set->get_it() as $game)
{
  echo $game['defender']."\n";
}

Most likely this is all you need:

foreach ($game_set->get_it() as $game)
{
  echo $game['defender']."\n";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文