gpt4 book ai didi

php - 从更多数组中选择唯一值

转载 作者:行者123 更新时间:2023-11-29 01:11:47 25 4
gpt4 key购买 nike

我有以下代码:

$get_countries = "SELECT country FROM blahs WHERE country IS NOT NULL ORDER BY country";
$data_get_countries = mysqli_query($dbc, $get_countries);

while ($row_get_countries = mysqli_fetch_array($data_get_countries)) {
$country_tabs = array_unique($row_get_countries);
foreach ($country_tabs as $country_tab) {
echo '<div>' . $country_tab . '</div>';
var_dump($country_tab);
var_dump($country_tabs);

}
}

现在 var_dump($country_tab) 输出:

string 'DE' (length=2)
string 'GB' (length=2)
string 'SE' (length=2)
string 'US' (length=2)
string 'US' (length=2)
string 'US' (length=2)
string 'US' (length=2)

和 var_dump($country_tabs):

array
0 => string 'DE' (length=2)
array
0 => string 'GB' (length=2)
array
0 => string 'SE' (length=2)
array
0 => string 'US' (length=2)
array
0 => string 'US' (length=2)
array
0 => string 'US' (length=2)
array
0 => string 'US' (length=2)

我想要实现的是让我的代码不显示相同的国家!array_unique($country_tabs) 不起作用,因为我在输出中有更多数组。

最佳答案

使用 SELECT DISTINCT country FROM blahs WHERE country IS NOT NULL ORDER BY country

它将删除每个重复值。

关于php - 从更多数组中选择唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11783444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com