?php
創(chuàng)新互聯(lián)公司專注于中大型企業(yè)的成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)和網(wǎng)站改版、網(wǎng)站營(yíng)銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開(kāi)發(fā)的融合,累計(jì)客戶1000+,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對(duì)接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開(kāi)發(fā),在前進(jìn)的路上,與客戶一起成長(zhǎng)!
$arr=array(6,3,53,5,3);
$arr2=array();
foreach($arr?as??$v){
if(!in_array($v,$arr2)){
$arr2[]=$v;
}
}
var_dump($arr2);
?
$arr2即為除掉重復(fù)值的結(jié)果
array_unique() 函數(shù)定義和用法
移除數(shù)組中的重復(fù)的值,并返回結(jié)果數(shù)組。
當(dāng)幾個(gè)數(shù)組元素的值相等時(shí),只保留第一個(gè)元素,其他的元素被刪除。
返回的數(shù)組中鍵名不變。
例子
?php
$a=array("a"="Cat","b"="Dog","c"="Cat");
print_r(array_unique($a));
?
輸出:Array ( [a] = Cat [b] = Dog )
$arr = array(
array(
array(
"stocknotifyId" = 1,
"sku" = '13809_BL_37',
"email" = 'huang@aaa.com'
),
array(
"stocknotifyId" = 3,
"sku" = '13809_BL_37',
"email" = 'hrheve@dfwef.com'
),
array(
"stocknotifyId" = 5,
"sku" = '13809_BL_37',
"email" = 'dfsfs@dfsf.com'
)
),
array(
array(
"stocknotifyId" = 2,
"sku" = '13809_B_39',
"email" = 'huang@aaa.com'
)
),
array(
array(
"stocknotifyId" = 4,
"sku" = '13809_BL_39',
"email" ='hrheve@dfwef.com'
)
)
);
$re = array();
foreach($arr as $a) {
foreach ($a as $v) {
$tmp_v = $v;
unset($tmp_v['email']);
if(isset($re[$v['email']])) {
$re[$v['email']][] = $tmp_v;
}else{
$re[$v['email']] = array($tmp_v);
}
}
}
print_r($re);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
!-- output --
Array
(
[huang@aaa.com] = Array
(
[0] = Array
(
[stocknotifyId] = 1
[sku] = 13809_BL_37
)
[1] = Array
(
[stocknotifyId] = 2
[sku] = 13809_B_39
)
)
[hrheve@dfwef.com] = Array
(
[0] = Array
(
[stocknotifyId] = 3
[sku] = 13809_BL_37
)
[1] = Array
(
[stocknotifyId] = 4
[sku] = 13809_BL_39
)
)
[dfsfs@dfsf.com] = Array
(
[0] = Array
(
[stocknotifyId] = 5
[sku] = 13809_BL_37
)
)
)