我正在爲撲克錦標賽構建一個排行榜(scorebored)。我的目標是將數據回顯到表格中,以顯示季節的分數和所有時間的分數。我希望桌子能夠以最高的賽季得分排列。 我得到的是一條錯誤信息:已聲明的鍵上未定義的索引錯誤
Notice: Undefined index: season in C:\wamp\www\UPT Site\leaders.php on line 11
當我print_r
從$allplayers
數組的數組,它表明,所有的球員陣列正確進去,包括[season]
鍵和值在線聲明6在下面的位...
任何人都可以請告訴我如何解決我的代碼? (請注意,真正的代碼中沒有行號,我只是在這裏添加它們來使討論更加容易)。
1 foreach($allplayers as $player){
2 $i = $player[1];
3 if (${"seasonplayerid" . $i}){
4 $sum = array_sum(${"seasonplayerid" . $i});}
5 //$sum = points this season.
6 ${"playerid" . $i}['season'] = $sum;
7 }
8 function val_sort($array,$key) {
9 //Loop through and get the values of our specified key
10 foreach($array as $k=>$v) {
11 $b[] = strtolower($v[$key]);
12 }
13 asort($b);
14 /* foreach($b as $k=>$v) {
15 $c[] = $array[$k];
16 }return $c;
17 */
18 }
19 $sorted = val_sort($allplayers, '[season]');
20 foreach($allplayers as $player){
21 $i = $player[1];
22 echo ("<tr><td>" . $player[0] . $t . ${"playerid" . $i}[3] . $t . ${"playerid" . $i}[4] . $t. ${"playerid" . $i}['season'] . $t. count(${"seasonplayerid" . $i}). "</td><tr>");
23 }
這裏是print_r
輸出陣列$playerid1
:
陣列([0] =>喬納森湯普森[1] => 1 [2] => 2015-S 3 [3] => 944 [4] => 7 [季節] => 470)
以下爲在陣列中的信息的密鑰:
/*
$allplayers is a multidimentional array, containing many arrays of players called $playerid1, $playerid2, $playerid3 etc
playerid1[0] = Player name
playerid1[1] = Player ID
playerid1[2] = Current season
playerid1[3] = total points earned
playerid1[4] = total games played games
playerid1[season] = points earned in current season
*/
包含您正在使用的數組,並且行號不是必需的;這裏的大多數人都可以算:) –
在$ allplayers中發佈數據 – rocky
@ Tunna182在'$ allplayers'陣列中沒有像'season'這樣的密鑰 – sandeepsure