Php 如何打印Gelocation Codeigniter的每个细节?
我正在尝试使用codeigniter从我的网站检索我的城市访客 下面是显示城市的代码Php 如何打印Gelocation Codeigniter的每个细节?,php,codeigniter,geolocation,Php,Codeigniter,Geolocation,我正在尝试使用codeigniter从我的网站检索我的城市访客 下面是显示城市的代码 $city = $this->geolocation->get_city(); 这里,地理定位的输出如下 array(11) { ["statusCode"]=>string(2) "OK" ["statusMessage"]=> string(0) "" ["ipAddress"]=> string(12) "202.60.21.15" ["countryCode"]=>
$city = $this->geolocation->get_city();
这里,地理定位的输出如下
array(11) { ["statusCode"]=>string(2) "OK" ["statusMessage"]=> string(0) "" ["ipAddress"]=> string(12) "202.60.21.15" ["countryCode"]=> string(2) "ID" ["countryName"]=> string(9) "Indonesia" ["regionName"]=> string(10) "Jawa Timur" ["cityName"]=> string(11) "Pacarkeling" ["zipCode"]=> string(5) "60132" ["latitude"]=> string(6) "-7.258" ["longitude"]=> string(7) "112.758" ["timeZone"]=> string(6) "+07:00" } OK202.67.41.25IDIndonesiaJawa
我正在使用
$cities = json_decode($city, true);
foreach ($cities as $c) {
echo $c;
}
输出是这样的
OK202.67.01.25IDIndonesiaJawa TimurPacarkeling60132-7.258112.758+07:00
如何从输出中获取每个数据?我想用Codeingiter格式打印地理定位库中的每个数据
Your Visitor Country : Indonesia
Your IP Visitor : 202.67.01.25
Your City Name : Pacarkeling
非常感谢:)您要阵列的钥匙吗?如果是这样,您可以这样做:
$city = $this->geolocation->get_city();
$city_info = json_decode($city, true);
foreach ($city_info as $key=>$value) {
echo 'Your ' . $key . ' : ' . $value . '<br>';
}
$city=$this->geolocation->get_city();
$city\u info=json\u decode($city,true);
foreach($city\u info as$key=>$value){
回显“您的“.$key.”:“.$value.”
;
}
是的,这是工作。但是,很抱歉,也许我的问题不完整,我的意思是如果只显示城市名称。。谢谢$city\u info['cityName']
我想您应该看看文档,以澄清一些基本概念。