我如何得到一个数组独特的价值? [英] How do i get unique value from an array?
本文介绍了我如何得到一个数组独特的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ a =阵列(A=>中猫,B=>中的狗,C=>中猫);
从上面的数组我需要一个人的价值的狗。我怎样才能从数组的独特价值?没有任何功能在PHP?...
谢谢
拉维
解决方案
$ a =阵列(A=>中猫,B=>中的狗 ,C=>中猫);
$计数= array_count_values($ A);
$结果=阵列();
的foreach($算作$关键=> $值){
如果($值=== 1){
$结果[] = $键;
}
}
//现在$结果只有$ a的唯一值的数组
的print_r($结果);
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
From the above array i need the value Dog alone. how can i get the unique value from an array?. is there any functions in php?...
Thanks Ravi
解决方案
$a = array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
$counted = array_count_values($a);
$result = array();
foreach($counted as $key => $value) {
if($value === 1) {
$result[] = $key;
}
}
//$result is now an array of only the unique values of $a
print_r($result);
这篇关于我如何得到一个数组独特的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文