我正在尝试使用来自一个 JSON 链接的值来填充其他 JSON 链接中的值,从而生成来自组合 JSON 的唯一值列表。我已经创建了完整的值列表,但是我很难在最终循环中找到仅显示唯一值的语法。任何帮助,将不胜感激。
$collection_string = file_get_contents("http://some_json_url.com/json");
$collection_list = json_decode($collection_string, true);
foreach ($collection_list as $col_lists => $col_list) {
$object_string = file_get_contents('http://another_json_url.com/'.$col_list['key'].'/json');
$object_list = json_decode($object_string, true);
$object_array = array();
foreach ($object_list as $objects => $object) {
$object_array [] = array_unique($object); //Returns "Warning: array_unique() expects parameter 1 to be array, string given in..."
echo '<li><a href="some_search_url/'.$object_array.'/search/">'.$object_array.'</a></li>'; //Returns "Array"
echo '<li><a href="some_search_url/'.$object.'/search/">'.$object.'</a></li>'; //Returns complete list
}
}
工作代码:
$collection_string = file_get_contents("http://some_json_url.com/json");
$collection_list = json_decode($collection_string, true);
$object_array = array();
foreach ($collection_list as $col_lists => $col_list) {
$object_string = file_get_contents('http://another_json_url.com/'.$col_list['key'].'/json');
$object_list = json_decode($object_string, true);
foreach ($object_list as $key => $value) {
array_push($object_array, $value);
}
}
$object_unique = array_unique($object_array);
natcasesort($object_unique);
foreach ($object_unique as $key => $value) {
echo '<li><a href="some_search_url/'.$value.'/search/">'.$value.'</a></li>';
}