您好,登錄后才能下訂單哦!
<?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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。