<?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>';
?>