可能重复:
Able to see a variable in print_r()'s output, but not sure how to access it in code
stdClass Object ( [geonames] => Array ( [0] => stdClass Object ( [countryName] => United States [adminCode1] => TX [fclName] => city, village,... [countryCode] => US [lng] => -97.3455673 [fcodeName] => populated place [distance] => 1.83381 [toponymName] => Greenock [fcl] => P [name] => Greenock [fcode] => PPL [geonameId] => 4695037 [lat] => 31.7662717 [adminName1] => Texas [population] => 0 ) ) )
这是我从print_r得到的结果($ results)。我需要获取[name]和[adminname1]值。 我已经尝试了几种方法,我只是继续得到数组{或数组...任何帮助,请
编辑:这是一个var_dump:
object(stdClass)#1 (1) { ["geonames"]=> array(1) { [0]=> object(stdClass)#2 (15) { ["countryName"]=> string(13) "United States" ["adminCode1"]=> string(2) "TX" ["fclName"]=> string(17) "city, village,..." ["countryCode"]=> string(2) "US" ["lng"]=> float(-97.3455673) ["fcodeName"]=> string(15) "populated place" ["distance"]=> string(7) "1.83381" ["toponymName"]=> string(8) "Greenock" ["fcl"]=> string(1) "P" ["name"]=> string(8) "Greenock" ["fcode"]=> string(3) "PPL" ["geonameId"]=> int(4695037) ["lat"]=> float(31.7662717) ["adminName1"]=> string(5) "Texas" ["population"]=> int(0) } } }