我有一个像这样的数组
0 => string '' (length=0)
1 => string 'nameMiddle' (length=10)
2 => string 'dsa' (length=3)
3 => string '' (length=0)
4 => string 'phoneFirst' (length=10)
5 => string 'addressStreet' (length=13)
6 => string 'addressCity' (length=11)
7 => string 'addressState' (length=12)
8 => string 'addressZip' (length=10)
9 => string 'status' (length=6)
10 => string 'gender' (length=6)
11 => string 'dateOfBirth' (length=11)
12 => string 'numberOfDependents' (length=18)
13 => string 'salary' (length=6)
14 => string 'startDate' (length=9)
15 => string 'ltdClass' (length=8)
16 => string 'deductionMedical' (length=16)
17 => string 'deductionDental' (length=15)
18 => string 'deductionVision' (length=15)
19 => string 'suppLyfCost' (length=11)
20 => string 'stdCost' (length=7)
21 => string 'effectiveDate' (length=13)
这些值最终将是使用array_combine的键,但我不能在array_combine上使用相同的键。如何检查数组是否具有相同的值如果是这样的话我怎样才能使值成为唯一的
0 => string '0'
3 => string '3'
感谢
答案 0 :(得分:0)
要使用其键替换为空或不唯一的值,请尝试:
foreach($array as $k => &$v) {
if(empty($v) || count(array_search($v, $array)) > 1) {
$v = $k;
}
}