変数を使用して配列名やキーを指定する方法を教えてください。私は数え切れないほどの時間を試みたと私はコードに入る前に、それはPHPで変数を使用して配列を指定するには?
を働くことはありません 、$ゲームは配列で、私はここで下
でそれを示して私のコードは、(私が配列の例を示しますですここでは下)
$increment = 0; //increment i use in a while loop +1 per loop starting at 0
$increment2 = increment - 1; // to get the game number i need to minus 1 from $increment,
//this works since the array starts at 0 and increment will be 1 when the while loop starts.
$gamestotal = $games[totalGames]; //This number is different everytime, it is always
//between 1-1000, it counts the number of a games a person has.
$gamesnpcommid = $games[$increment2][npcommid]; //each game has a unique code, i cURL this
//info from Sony servers and return it in an array (array example below) This is the part
//that is not working, to help understand please check array first, this variable is used
//in the while loop and i need it to start at array 0 and keep returning the unique code
//until the loops stops at the final array number.
//はすべてが完全に正常に動作しているが、配列参照が動作していない
while($increment<$gamestotal)
if($increment % 2 == 0){
$increment=$increment+1;
echo "<tr>";
echo "<td style='background-color:#e6e8fa'>";
echo $gamesnpcommid;
echo "</td>";
echo "</tr>";
}
else
{$increment=$increment+1;
echo "<tr>";
echo "<td style='background-color:adeaea'>";
echo $gamesnpcommid;
echo "</td>";
echo "</tr>";
}
echo "</table>";
ループ(ですなぜ、例えば、その後、$increment2 = 2
場合、誰かが私に説明でき
Array
(
[totalGames] => 110
[0] => Array
(
[npcommid] => NPWR00507_00
[platinum] => 0
[gold] => 1
[silver] => 11
[bronze] => 32
[total] => 44
[lastupdated] => 1329258539
)
[1] => Array
(
[npcommid] => NPWR01140_00
[platinum] => 1
[gold] => 4
[silver] => 8
[bronze] => 29
[total] => 42
[lastupdated] => 1328586022
)
[2] => Array
(
[npcommid] => NPWR01118_00
[platinum] => 0
[gold] => 0
[silver] => 3
[bronze] => 8
[total] => 11
[lastupdated] => 1328067349
)
)
、配列変数$games
に格納されて
:ここでは)は、配列$games
がどのように見えることができるものの一例です$games[$increment2][npcommid]
を使用して配列を参照しようとすると、配列のようにNPWR01118_00が返されませんか? しかし、私は$games[2][npcommid]
を使用していますか? 私は徹底的なデバッグを行っており、配列の動作を知っていますが、私はこの時点で困っています。
に今働いています。編集ボックスの上のオレンジ色の疑問符のアイコンをクリックすると、指示が表示されます。私はあなたが今持っているものを読むことを試みるつもりはない。 – Quentin
increment2は-1であり、コード内で変更されたことはありません...したがって、コード内のあなたの位置で変更されていない可能性がありますか? – Neysor
なぜこの配列をループする代わりに 'foreach'ループを使用しないのですか? – Svish