[英]How to print out the unique values of a PHP array?
$country
$country
的数组中列出了我的国家/ $country
When I do dd($country);
当我做
dd($country);
I see this 我看到这个
I want to print out all country name of that array ( unique value only ) 我想打印出该数组的所有国家/地区名称(仅唯一值)
I tried echo (array_unique(array_values($country)));
我试过了
echo (array_unique(array_values($country)));
But I got an error 但是我有一个错误
ErrorException (E_UNKNOWN)
Array to string conversion
You can't echo
an array. 您无法
echo
数组。 It's not a string. 不是字符串。
// There's no need to use array_values
$uniqueValues = array_unique($continent);
foreach($uniqueValues as $country){
echo $country, '<br>';
}
Since I have my array from $countries[$k] = $v['hq_country']['name'];
由于我的数组来自
$countries[$k] = $v['hq_country']['name'];
Printing them out, I just need to do this 打印出来,我只需要这样做
foreach(array_unique($countries) as $country){
echo $country ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.