2016-12-01 92 views
0

我有問題如何在表中顯示的陣列它腓陣列讀取概率

MY代碼:

Array ([server_1] => Array ([_tutor_debug_level] => 0 [_tutor_examine_time] => 0.5 [_tutor_hint_interval_time] => 10.0 [_tutor_look_angle] => 10 [_tutor_look_distance] => 200 [_tutor_message_character_display_time_coefficient] => 0.07 [_tutor_message_minimum_display_time] => 1 [_tutor_message_repeats] => 5 [_tutor_view_distance] => 1000 [allow_spectators] => 1.0 [amx_client_languages] => 1 [amx_language] => en [amx_nextmap] => de_inferno [amx_ptb_version] => 1.8b3 [amx_timeleft] => 25:48 [amxmodx_version] => 1.8.2 [coop] => 0 [deathmatch] => 1 [decalfrequency] => 30 [dedicated] => d [dp_version] => 0.9.543 [edgefriction] => 2 [game_descr] => gametracker.rs [game_dir] => cstrike [gq_address] => 176.57.188.22 [gq_dedicated] => d [gq_gametype] => [gq_hostname] => ..:: LS Public Server ::.. #1 [gq_mapname] => de_nuke [gq_maxplayers] => 32 [gq_mod] => cstrike [gq_numplayers] => 30 [gq_online] => 1 [gq_password] => 0 [gq_port] => 27022 [gq_prot] => source [gq_type] => cs [hostage_debug] => 0 [hostage_stop] => 0 [hostname] => ..:: LS Public Server ::.. #1 [humans_join_team] => any [kgbbots] => 1 [ks_skore] => Ks Skore Zero by ScrappeR skype: elbasan.f v1.0 [map] => de_nuke [map_spawns] => T(20) CT(20) [max_players] => 32 [max_queries_sec] => 1 [max_queries_sec_global] => 1 [max_queries_window] => 1 [metamod_version] => 1.21-am [mp_allowmonsters] => 0 [mp_autokick] => 0 [mp_autokick_timeout] => -1 [mp_autoteambalance] => 1 [mp_buytime] => 0.75 [mp_c4timer] => 35 [mp_chattime] => 3 [mp_consistency] => 1 [mp_fadetoblack] => 0 [mp_flashlight] => 0 [mp_footsteps] => 1 [mp_forcecamera] => 2 [mp_forcechasecam] => 2 [mp_fragsleft] => 0 [mp_freezetime] => 2 [mp_friendlyfire] => 0 [mp_ghostfrequency] => 0.1 [mp_hostagepenalty] => 0 [mp_kickpercent] => 0.66 [mp_limitteams] => 0 [mp_logdetail] => 0 [mp_logfile] => 1 [mp_logmessages] => 1 [mp_mapvoteratio] => 0.66 [mp_maxrounds] => 0 [mp_mirrordamage] => 0 [mp_playerid] => 0 [mp_roundtime] => 2 [mp_slaylosers] => 1 [mp_startmoney] => 1400 [mp_timeleft] => 0 [mp_timelimit] => 40 [mp_tkpunish] => 0 [mp_windifference] => 1 [mp_winlimit] => 0 [num_bots] => 2 [num_players] => 30 [num_rules] => 29791 [os] => l [password] => 0 [pausable] => 0 [players] => Array ([0] => Array ([id] => 0 [name] => salkiiiii:) [score] => 29 [time] => 889.31640625 [gq_name] => salkiiiii:) [gq_score] => 29 [gq_ping] =>) [1] => Array ([id] => 0 [name] => SempTex [score] => 15 [time] => 1228.37890625 [gq_name] => SempTex [gq_score] => 15 [gq_ping] =>) [2] => Array ([id] => 0 [name] => ProfeSSionaL. [score] => 10 [time] => 1853.953125 [gq_name] => ProfeSSionaL. [gq_score] => 10 [gq_ping] =>) [3] => Array ([id] => 0 [name] => Tarzani [score] => 10 [time] => 1697.60546875 [gq_name] => Tarzani [gq_score] => 10 [gq_ping] =>) [4] => Array ([id] => 0 [name] => diamanti [score] => 9 [time] => 890.12109375 [gq_name] => diamanti [gq_score] => 9 [gq_ping] =>) [5] => Array ([id] => 0 [name] => Mally [score] => 8 [time] => 436.2421875 [gq_name] => Mally [gq_score] => 8 [gq_ping] =>) [6] => Array ([id] => 0 [name] => bARCELONA' [score] => 8 [time] => 1786.72265625 [gq_name] => bARCELONA' [gq_score] => 8 [gq_ping] =>) [7] => Array ([id] => 0 [name] => kInG [score] => 6 [time] => 451.72265625 [gq_name] => kInG [gq_score] => 6 [gq_ping] =>) [8] => Array ([id] => 0 [name] => Wassabi [score] => 5 [time] => 1243.27734375 [gq_name] => Wassabi [gq_score] => 5 [gq_ping] =>) [9] => Array ([id] => 0 [name] => GJYS [score] => 4 [time] => 7076.44921875 [gq_name] => GJYS [gq_score] => 4 [gq_ping] =>) [10] => Array ([id] => 0 [name] => PO DEE [score] => 2 [time] => 2588.15234375 [gq_name] => PO DEE [gq_score] => 2 [gq_ping] =>) [11] => Array ([id] => 0 [name] => TrapQueen [score] => 2 [time] => 890.21875 [gq_name] => TrapQueen [gq_score] => 2 [gq_ping] =>) [12] => Array ([id] => 0 [name] => (1)audi [score] => 1 [time] => 740.625 [gq_name] => (1)audi [gq_score] => 1 [gq_ping] =>) [13] => Array ([id] => 0 [name] => mevludin [score] => 1 [time] => 2053.35546875 [gq_name] => mevludin [gq_score] => 1 [gq_ping] =>) [14] => Array ([id] => 0 [name] => **DaN1 P0W3R** [score] => 0 [time] => 2584.4765625 [gq_name] => **DaN1 P0W3R** [gq_score] => 0 [gq_ping] =>) [15] => Array ([id] => 0 [name] => -_- [score] => 0 [time] => 1044.75390625 [gq_name] => -_- [gq_score] => 0 [gq_ping] =>) [16] => Array ([id] => 0 [name] => >>>AMG<<< [score] => 0 [time] => 8932.015625 [gq_name] => >>>AMG<<< [gq_score] => 0 [gq_ping] =>) [17] => Array ([id] => 0 [name] => >>MiTroBoYSs<< [score] => 0 [time] => 18368.73828125 [gq_name] => >>MiTroBoYSs<< [gq_score] => 0 [gq_ping] =>) [18] => Array ([id] => 0 [name] => [email protected][email protected] [score] => 0 [time] => 1043.4375 [gq_name] => [email protected][email protected] [gq_score] => 0 [gq_ping] =>) [19] => Array ([id] => 0 [name] => GiLAN [score] => 0 [time] => 4353.34375 [gq_name] => GiLAN [gq_score] => 0 [gq_ping] =>) [20] => Array ([id] => 0 [name] => ISCO [score] => 0 [time] => 30895.46484375 [gq_name] => ISCO [gq_score] => 0 [gq_ping] =>) [21] => Array ([id] => 0 [name] => Mr.I [score] => 0 [time] => 3309.33203125 [gq_name] => Mr.I [gq_score] => 0 [gq_ping] =>) [22] => Array ([id] => 0 [name] => Tony Cortes [score] => 0 [time] => 216.08203125 [gq_name] => Tony Cortes [gq_score] => 0 [gq_ping] =>) [23] => Array ([id] => 0 [name] => ViRuSi [score] => 0 [time] => 186.375 [gq_name] => ViRuSi [gq_score] => 0 [gq_ping] =>) [24] => Array ([id] => 0 [name] => ZekiGrandFather! [score] => 0 [time] => 154.90234375 [gq_name] => ZekiGrandFather! [gq_score] => 0 [gq_ping] =>) [25] => Array ([id] => 0 [name] => c0d3 [score] => 0 [time] => 53075.8046875 [gq_name] => c0d3 [gq_score] => 0 [gq_ping] =>) [26] => Array ([id] => 0 [name] => shuajbbiceps [score] => 0 [time] => 889.22265625 [gq_name] => shuajbbiceps [gq_score] => 0 [gq_ping] =>) [27] => Array ([id] => 0 [name] => theun [score] => 0 [time] => 890.125 [gq_name] => theun [gq_score] => 0 [gq_ping] =>) [28] => Array ([id] => 0 [name] => timi [score] => 0 [time] => 2130.37890625 [gq_name] => timi [gq_score] => 0 [gq_ping] =>) [29] => Array ([id] => 0 [name] => www.lspublic.com [score] => 0 [time] => 53075.8046875 [gq_name] => www.lspublic.com [gq_score] => 0 [gq_ping] =>)) [protocol] => 48 [round_version] => 1.3 [secure] => 1 [steamappid] => 10 [sv_accelera] => 5 [sv_aim] => 0 [sv_airaccelerate] => 10 [sv_allowupload] => 1 [sv_alltalk] => 0 [sv_bounce] => 1 [sv_cheats] => 0 [sv_clienttrace] => 1 [sv_contact] => [sv_friction] => 4 [sv_gravity] => 800 [sv_logblocks] => 0 [sv_maxrate] => 80000 [sv_maxspeed] => 900 [sv_minrate] => 70000 [sv_password] => 0 [sv_proxies] => 0 [sv_restart] => 0 [sv_restartround] => 0 [sv_stepsize] => 18 [sv_stopspeed] => 75 [sv_uploadmax] => 0.5 [sv_voiceenable] => 1 [sv_wateraccelerate] => 10 [sv_waterfriction] => 1 [utor_bomb_viewable_check_interval] => 0.5 [version] => 49 [vtc_version] => 80)) 

我不想顯示該玩家陣列([玩家] =>數組()

我想這個代碼,但不工作,他找到我唯一的結果:

<table> 
<?php 
    require_once('../gameq.php'); 

    $servers = array('server_'.$server_id => array($server_game, $server_ip, $server_port)) or die(mysql_error()); 

    $gq = new GameQ(); 

    $gq->addServers($servers); 

    $gq->setOption('timeout', 250); 

    $gq->setFilter('normalise'); 

    $gq->setFilter('sortplayers'); 

    $data = $gq->requestData(); 


    if($data['server_'.$server_id]['gq_online'] == "1"){ 

     foreach ($data as $datas => $value) { 

         echo "<tr> 
          <td>".htmlspecialchars($datas)."</td> 
          <td>".htmlspecialchars($value)."</td> 
           <tr>"; 
       } 

     } 

?> 
</table> 
+0

它看起來像這將取決於'值$ server_id'。那個集合在哪裏? –

+0

$ server_id,$ server_ip,$ server_port,否則我設置在頁面頂部 –

+0

我修正了它..... –

回答

0

你已經有了一個多dimensiona server1的l數組。您將需要構建多個foreach循環來遍歷數組的每個級別。

你將不得不玩這個代碼,它應該讓你開始。

if($data['server_'.$server_id]['gq_online'] == "1"){ 

foreach ($data as $datas => $value) { 
    foreach($value as $k=>$v) { 
         echo "<tr> 
         <td>".htmlspecialchars($k)."</td> 
         <td>".htmlspecialchars($v)."</td> 
          <tr>"; 
    } 
} 

你也可以這樣做。這將從數組的第二級開始,只要你知道server_1總是首先出現。我不推薦這種方式。

if($data['server_'.$server_id]['gq_online'] == "1"){ 

foreach ($data['server_1'] as $datas => $value) { 
    foreach($value as $k=>$v) { 
         echo "<tr> 
         <td>".htmlspecialchars($k)."</td> 
         <td>".htmlspecialchars($v)."</td> 
          <tr>"; 
    } 
} 
0

呀,但他沒有得到的結果很好看錶下的變量顯示值TD

他看起來:http://prntscr.com/de9agw

<table width="100%"> 
                  <tbody> 
<tr> 
<th>Variable</th> 
<th>Value</th> 
</tr> 
<tr> 
         <td></td> 
         <td>sv_friction</td> 
          </tr><tr></tr><tr> 
         <td>0.5</td> 
         <td>sv_voiceenable</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_debug_level</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_examine_time</td> 
         <td>0.5</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_hint_interval_time</td> 
         <td>10.0</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_look_angle</td> 
         <td>10</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_look_distance</td> 
         <td>200</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_message_character_display_time_coefficient</td> 
         <td>0.07</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_message_minimum_display_time</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_message_repeats</td> 
         <td>5</td> 
          </tr><tr></tr><tr> 
         <td>_tutor_view_distance</td> 
         <td>1000</td> 
          </tr><tr></tr><tr> 
         <td>allow_spectators</td> 
         <td>1.0</td> 
          </tr><tr></tr><tr> 
         <td>0</td> 
         <td>sv_stepsize</td> 
          </tr><tr></tr><tr> 
         <td>amx_client_languages</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>amx_language</td> 
         <td>en</td> 
          </tr><tr></tr><tr> 
         <td>amx_nextmap</td> 
         <td>de_dust2</td> 
          </tr><tr></tr><tr> 
         <td>amx_ptb_version</td> 
         <td>1.8b3</td> 
          </tr><tr></tr><tr> 
         <td>amx_timeleft</td> 
         <td>01:58</td> 
          </tr><tr></tr><tr> 
         <td>amxmodx_version</td> 
         <td>1.8.2</td> 
          </tr><tr></tr><tr> 
         <td>coop</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>deathmatch</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>decalfrequency</td> 
         <td>30</td> 
          </tr><tr></tr><tr> 
         <td>dedicated</td> 
         <td>d</td> 
          </tr><tr></tr><tr> 
         <td>dp_version</td> 
         <td>0.9.543</td> 
          </tr><tr></tr><tr> 
         <td>edgefriction</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>game_descr</td> 
         <td>gametracker.rs</td> 
          </tr><tr></tr><tr> 
         <td>game_dir</td> 
         <td>cstrike</td> 
          </tr><tr></tr><tr> 
         <td>gq_address</td> 
         <td>176.57.188.22</td> 
          </tr><tr></tr><tr> 
         <td>gq_dedicated</td> 
         <td>d</td> 
          </tr><tr></tr><tr> 
         <td>gq_gametype</td> 
         <td></td> 
          </tr><tr></tr><tr> 
         <td>gq_hostname</td> 
         <td>..:: LS Public Server ::.. #1</td> 
          </tr><tr></tr><tr> 
         <td>gq_mapname</td> 
         <td>de_inferno</td> 
          </tr><tr></tr><tr> 
         <td>gq_maxplayers</td> 
         <td>32</td> 
          </tr><tr></tr><tr> 
         <td>gq_mod</td> 
         <td>cstrike</td> 
          </tr><tr></tr><tr> 
         <td>gq_numplayers</td> 
         <td>28</td> 
          </tr><tr></tr><tr> 
         <td>gq_online</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>gq_password</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>gq_port</td> 
         <td>27022</td> 
          </tr><tr></tr><tr> 
         <td>gq_prot</td> 
         <td>source</td> 
          </tr><tr></tr><tr> 
         <td>gq_type</td> 
         <td>cs</td> 
          </tr><tr></tr><tr> 
         <td>hostage_debug</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>hostage_stop</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>hostname</td> 
         <td>..:: LS Public Server ::.. #1</td> 
          </tr><tr></tr><tr> 
         <td>humans_join_team</td> 
         <td>any</td> 
          </tr><tr></tr><tr> 
         <td>kgbbots</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>ks_skore</td> 
         <td>Ks Skore Zero by ScrappeR skype: elbasan.f v1.0</td> 
          </tr><tr></tr><tr> 
         <td>map</td> 
         <td>de_inferno</td> 
          </tr><tr></tr><tr> 
         <td>map_spawns</td> 
         <td>T(20) CT(20)</td> 
          </tr><tr></tr><tr> 
         <td>max_players</td> 
         <td>32</td> 
          </tr><tr></tr><tr> 
         <td>max_queries_sec</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>max_queries_sec_global</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>max_queries_window</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>metamod_version</td> 
         <td>1.21-am</td> 
          </tr><tr></tr><tr> 
         <td>mp_allowmonsters</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_autokick</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_autokick_timeout</td> 
         <td>-1</td> 
          </tr><tr></tr><tr> 
         <td>mp_autoteambalance</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_buytime</td> 
         <td>0.75</td> 
          </tr><tr></tr><tr> 
         <td>mp_c4timer</td> 
         <td>35</td> 
          </tr><tr></tr><tr> 
         <td>mp_chattime</td> 
         <td>3</td> 
          </tr><tr></tr><tr> 
         <td>mp_consistency</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_fadetoblack</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_flashlight</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_footsteps</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_forcecamera</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>mp_forcechasecam</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>mp_fragsleft</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_freezetime</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>mp_friendlyfire</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_ghostfrequency</td> 
         <td>0.1</td> 
          </tr><tr></tr><tr> 
         <td>mp_hostagepenalty</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_kickpercent</td> 
         <td>0.66</td> 
          </tr><tr></tr><tr> 
         <td>mp_limitteams</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_logdetail</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_logfile</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_logmessages</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_mapvoteratio</td> 
         <td>0.66</td> 
          </tr><tr></tr><tr> 
         <td>mp_maxrounds</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_mirrordamage</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_playerid</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_roundtime</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>mp_slaylosers</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_startmoney</td> 
         <td>1400</td> 
          </tr><tr></tr><tr> 
         <td>mp_timeleft</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_timelimit</td> 
         <td>40</td> 
          </tr><tr></tr><tr> 
         <td>mp_tkpunish</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>mp_windifference</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>mp_winlimit</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>num_bots</td> 
         <td>2</td> 
          </tr><tr></tr><tr> 
         <td>num_players</td> 
         <td>28</td> 
          </tr><tr></tr><tr> 
         <td>num_rules</td> 
         <td>29791</td> 
          </tr><tr></tr><tr> 
         <td>os</td> 
         <td>l</td> 
          </tr><tr></tr><tr> 
         <td>password</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>pausable</td> 
         <td>0</td> 
          </tr><tr></tr><tr> 
         <td>players</td> 
         <td></td> 
          </tr><tr></tr><tr> 
         <td>protocol</td> 
         <td>48</td> 
          </tr><tr></tr><tr> 
         <td>round_version</td> 
         <td>1.3</td> 
          </tr><tr></tr><tr> 
         <td>secure</td> 
         <td>1</td> 
          </tr><tr></tr><tr> 
         <td>steamappid</td> 
         <td>10</td> 
          </tr><tr></tr><tr> 
         <td>sv_accelerate</td> 
         <td>sv_aim</td> 
          </tr><tr></tr><tr> 
         <td>utor_bomb_viewable_check_interval</td> 
         <td>0.5</td> 
          </tr><tr></tr><tr> 
         <td>version</td> 
         <td>49</td> 
          </tr><tr></tr><tr> 
         <td>1</td> 
         <td>sv_waterfriction</td> 
          </tr><tr></tr><tr> 
         <td>2</td> 
         <td>vtc_version</td> 
          </tr><tr></tr><tr> 
         <td>3</td> 
         <td>sv_gravity</td> 
          </tr><tr></tr><tr> 
         <td>4</td> 
         <td>sv_logblocks</td> 
          </tr><tr></tr><tr> 
         <td>5</td> 
         <td>sv_maxspeed</td> 
          </tr><tr></tr><tr> 
         <td>6</td> 
         <td>sv_minrate</td> 
          </tr><tr></tr><tr> 
         <td>7</td> 
         <td>sv_password</td> 
          </tr><tr></tr><tr> 
         <td>8</td> 
         <td>sv_stopspeed</td> 
          </tr><tr></tr><tr> 
         <td>9</td> 
         <td>sv_uploadmax</td> 
          </tr><tr></tr><tr> 
         <td>10</td> 
         <td></td> 
          </tr><tr></tr></tbody></table>