<?php
//查询ip归属地
function ipclient($ip){
$url = "http://api.k780.com:88/?app=ip.get&ip=$ip&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
$return = file_get_contents($url);
$arr = json_decode($return,true);
$arrs = explode(",",$arr['result']['area_style_areanm']);
return $arrs[1];
}
$array = array();
$iparray = array('1'=>'220.181.111.85', '2'=>'220.181.111.86', '3'=>'202.104.149.156', '4'=>'42.120.194.11', '5'=>'121.14.24.241');
//转变数组
foreach($iparray as $val){
$iparrs[] = array('address' => ipclient($val),'ip'=>$val);
}
$area = $re = $persons = array();
foreach ($iparrs as $key=>$val) {
$area[] = $val['address'];
}
$area = array_unique($area); //获取地区数组集合
foreach ($iparrs as $key=>$val) {
foreach ($area as $area_key=>$area_val) {
if ($val['address'] == $area_val) {
$persons[$area_key][] = $val['ip'];
$re[$area_key] = array(
'address' => $area_val,
'persons' => $persons[$area_key],
);
}
}
}
$re = array_values($re);
echo '<pre>';
print_r($re);
echo '<pre>';
?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。