Php从数组中获取
我有个小问题,我无法从数组中获取信息。 这是我使用var_dump变量时的结果Php从数组中获取,php,Php,我有个小问题,我无法从数组中获取信息。 这是我使用var_dump变量时的结果 array(1) { ["server"]=> array(34) { ["dedicated"]=> string(1) "d" ["game_descr"]=> string(14) "Counter-Strike" ["game_dir"]=> string(7) "cstrike" ["gq_address"]=> string(1
array(1) {
["server"]=> array(34) {
["dedicated"]=> string(1) "d"
["game_descr"]=> string(14) "Counter-Strike"
["game_dir"]=> string(7) "cstrike"
["gq_address"]=> string(13) "185.119.89.91"
["gq_dedicated"]=> string(1) "d"
["gq_gametype"]=> string(14) "Counter-Strike"
["gq_hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["gq_joinlink"]=> string(36) "steam://connect/185.119.89.91:27031/"
["gq_mapname"]=> string(8) "de_dust2"
["gq_maxplayers"]=> int(32)
["gq_mod"]=> string(7) "cstrike"
["gq_name"]=> string(18) "Counter-Strike 1.6"
["gq_numplayers"]=> int(32)
["gq_online"]=> bool(true)
["gq_password"]=> int(0)
["gq_port_client"]=> int(27031)
["gq_port_query"]=> int(27031)
["gq_protocol"]=> string(6) "source"
["gq_transport"]=> string(3) "udp"
["gq_type"]=> string(4) "cs16"
["hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["map"]=> string(8) "de_dust2"
["max_players"]=> int(32)
["num_bots"]=> int(0)
["num_players"]=> int(32)
["os"]=> string(1) "l"
["password"]=> int(0)
["players"]=> array(0) { }
["port"]=> int(27031)
["protocol"]=> int(48)
["secure"]=> int(1)
["steamappid"]=> int(10)
["teams"]=> array(0) { }
["version"]=> string(13) "1.1.2.7/Stdio"
}
}
例如,如何获取主机名?
我试过像$info['hostname']
,$info[0]['hostname']代码>但什么都不起作用,为什么
数组中有一个东西
…这是另一个包含34个元素的数组
您正在忽略外部数组。您需要获取内部数组,然后从中访问所需的项
$info['server']['hostname']
请分享你的尝试。很明显,您丢失了一个数组键
["server"]=> array(34) { ... }
$info['server']['hostname']