如何在 PHP for 循环中递增 1 和 2

How to increment by 1 and by 2 in PHP for loop

我正在尝试在同一个 for 循环中递增两个单独的数字。例如我希望第一个数字是:

0,2,4,6,8,10 etc

我希望第二个数字是:

1,3,5,7,9 etc

我已经尝试了此处建议的方法,但可以正常工作:

How to increment a number by 2 in a PHP For Loop

到目前为止我的代码:

$count = count($toyList);
echo $count;
for($i=0; $i<$count; $i++){
    $json = '{"toy": {"toyname":"' . $toyList[$i+2] . ',"status":"' . $toyList[$i+3] . '"}}';
}

如有任何帮助,我们将不胜感激。谢谢。

引入一个额外的变量,并在你完成任何你想做的事情后在循环中增加它。我手头没有 PHP 的环境,但它应该看起来像这样:

$count = count($toyList);
echo $count;
$j = 1;
for($i=0; $i<$count; $i++){
    $json = '{"toy": {"toyname":"' . $toyList[$i+2] . ',"status":"' .    $toyList[$i+3] . '"}}';
    $j = $j + 2;
}