このスクリプトは、多次元配列を取得し、値を反復処理することになっています。
配列のサイズは 10 で、各要素には連想配列が含まれている必要があります。
$games[0] => array('foo' => 'bar')
$games[1] => array('foo1' => 'bar1')
etc..
この例では、while ループは 5 回反復する必要があります。for ループは、while ループの反復ごとに 10 回反復する必要があります。
だから私はエコーが次のようになることを期待しています:
countwhile = 5 countfor = 50 totalgames = 50
しかし、私は実際に得ています
countwhile = 5 countfor = 150 totalgames = 150
$games 配列は問題ではないと思います。以前に以下でその呼び出しを行い、print_r を使用してコンテンツを表示したことがあり、期待どおりであるためです。
このコード全体は、私の index.php ページにあるように、関数またはクラスに含まれていません。変数のスコープに問題があるのでしょうか?
$totalruns = 5;
$endindx = 10;
$startindx = 0;
$countwhile = 0;
$countfor = 0;
$totalfilesize = 0;
$totalgames = 0;
$sizeof = 0;
while($totalruns > 0)
{
$games = $feedHandler->getGames($startindx, $endindx);
$sizeof = sizeof($games);
for($i=0; $i<$sizeof; $i++)
{
$totalfilesize += $games[$i]['swf_file_size'];
$countfor++;
}
$startindx += 10;
$endindx += 10;
$totalruns -= 1;
$totalgames += $sizeof;
unset($games);
}
echo'<p>' . ' countwhile = ' . $countwhile . ' countfor = ' . $countfor . '</p>';