在php中从关联数组中消除具有相同值的重复键
最好使用在php中从关联数组中消除具有相同值的重复键,php,arrays,multidimensional-array,associative-array,Php,Arrays,Multidimensional Array,Associative Array,最好使用@mark,否则您也可以尝试 Array ( [0] => Zimbabwe [country] => Zimbabwe [1] => 2 [counts] => 2 ) Array ( [0] => Tunisia [country] => Tunisia [1] => 6 [counts] => 6 ) I want output like below: Arra
@mark
,否则您也可以尝试
Array
(
[0] => Zimbabwe
[country] => Zimbabwe
[1] => 2
[counts] => 2
)
Array
(
[0] => Tunisia
[country] => Tunisia
[1] => 6
[counts] => 6
)
I want output like below:
Array
(
[country] => Zimbabwe
[counts] => 2
)
Array
(
[country] => Tunisia
[counts] => 6
)
$a=数组
(
0=>“津巴布韦”,
“国家”=>“津巴布韦”,
1=> 2,
“计数”=>2,
);
函数myfun($array){
$check=array();
foreach($k=>v的数组){
if(在数组中($v,$check)){
未设置($array[$k]);
}
数组推送($check,$v);
}
返回$array;
}
$a=我的乐趣($a);
回声';
印刷费($a);
尝试使用
while($rowCountry = mssql_fetch_array($resultCountryCount), MSSQL_ASSOC){
print_r($rowCountry);
}
或
当您从数据库中检索数据时(您可能正在使用
mysql\u fetch\u数组()
或mysqli\u fetch\u数组()
调用,不是吗),请让fetch返回关联数组,而不是使用while($rowCountry=mssql\u fetch\u数组($resultCountry)){print\r($rowCountry)}.谢谢你的邀请help@MarkBaker如果您使用的是mysql\u fetch\u array
;的话,您的建议要比我的好得多@马克贝克是100%正确的。大眼睛。
while($rowCountry = mssql_fetch_array($resultCountryCount), MSSQL_ASSOC){
print_r($rowCountry);
}
while($rowCountry = mssql_fetch_assoc($resultCountryCount)){
print_r($rowCountry);
}