변수를 사용하여 배열 이름이나 키를 지정하는 방법에 대한 도움이 필요합니까? 내가 셀 수없이 많은 시간을 시도하고 내가 코드에 도착하기 전에 그것이 결코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>";
모두 완전히 잘 작동하지만, 루프 배열 참조가 작동하지 않는 (인 210,403,210)은, 여기에 배열 $games
이 어떻게 할 수 있는지의 예입니다
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
에 저장하는 이유, 예를 들어, $increment2 = 2
다음 $games[$increment2][npcommid]
을 사용하여 배열을 참조하려고하면 배열에서 NPWR01118_00을 반환하지 않습니까? 그러나 $games[2][npcommid]
을 사용할 때 작동합니까? 철저한 디버깅 작업을 수행했으며 배열 작동을 알았지 만이 시점에서 난처한 상황입니다.
지금 일하고 있습니다. 입력란 위의 주황색 물음표 아이콘을 클릭하면 안내가 나타납니다. 나는 지금 당신이 가진 것을 읽으 려하지 않을 것입니다. – Quentin
increment2는 -1이며 코드에서 변경되지 않습니다 ... 코드에서 사용자의 위치가 변경되지 않았습니까? – Neysor
대신이 배열을 반복하기 위해'foreach' 루프를 사용하지 않으시겠습니까? – Svish