Php 如何检测阵列中的重复ID? 函数getposts($search){ $url=”http://search.twitter.com/search.json?q=“$search.”包含实体=true,结果类型=mixed”; $value=文件内容($url); $array=json_decode($value,true); foreach($array['results']作为$id){ $uniquearray[]=array_unique($id); } 对于($i=0;$i
它确实有效。我的错误是我试图在循环本身中过滤它。当我从过滤器中取出array_unique时,它有效Php 如何检测阵列中的重复ID? 函数getposts($search){ $url=”http://search.twitter.com/search.json?q=“$search.”包含实体=true,结果类型=mixed”; $value=文件内容($url); $array=json_decode($value,true); foreach($array['results']作为$id){ $uniquearray[]=array_unique($id); } 对于($i=0;$i,php,arrays,json,unique,Php,Arrays,Json,Unique,它确实有效。我的错误是我试图在循环本身中过滤它。当我从过滤器中取出array_unique时,它有效 function getposts($search){ $url = "http://search.twitter.com/search.json?q=".$search."&include_entities=true&result_type=mixed"; $value = file_get_contents($url); $array = json_d
function getposts($search){
$url = "http://search.twitter.com/search.json?q=".$search."&include_entities=true&result_type=mixed";
$value = file_get_contents($url);
$array = json_decode($value, true);
foreach($array['results'] as $id){
$uniquearray[] = array_unique($id);
}
for($i=0;$i<count($uniquearray);$i++){
$output .= $uniquearray[$i]['from_user_id'];
$output .= "<br />";
}
return $output;
}
我把它做得更短、更干净,让它只返回一个数组。它确实有效。我的错误是我试图在循环本身中对它进行过滤。当我从过滤器中取出array_unique时,它起了作用
function getposts($search){
$url = "http://search.twitter.com/search.json?q=".$search."&include_entities=true&result_type=mixed";
$value = file_get_contents($url);
$array = json_decode($value, true);
foreach($array['results'] as $id){
$uniquearray[] = array_unique($id);
}
for($i=0;$i<count($uniquearray);$i++){
$output .= $uniquearray[$i]['from_user_id'];
$output .= "<br />";
}
return $output;
}
我把它做得更短、更干净,让它只返回一个数组。我也做了类似的回答 您可以根据您的问题调整此选项
<?php
function getids($search){
$url = "http://search.twitter.com/search.json?q=".$search."&include_entities=true&result_type=mixed";
$value = file_get_contents($url);
$array = json_decode($value, true);
$uniquearray = array();
for($i=0;$i<count($array['results']);$i++){
$uniquearray[] = $array['results'][$i]['from_user_id'];
}
$uniquearray = array_unique($uniquearray);
return $uniquearray;
}
?>
我也做了类似的回答 您可以根据您的问题调整此选项
<?php
function getids($search){
$url = "http://search.twitter.com/search.json?q=".$search."&include_entities=true&result_type=mixed";
$value = file_get_contents($url);
$array = json_decode($value, true);
$uniquearray = array();
for($i=0;$i<count($array['results']);$i++){
$uniquearray[] = $array['results'][$i]['from_user_id'];
}
$uniquearray = array_unique($uniquearray);
return $uniquearray;
}
?>
array\u unique()
不会过滤任何内容。它将返回相同的数组。在最终结果中,您将看到相同的数据。array\u unique()
不会过滤任何内容。它将返回相同的数组。在最终结果中,您将看到相同的数据。