时间:2021-07-01 10:21:17 帮助过:17人阅读
$ar = array (
0 =>
array (
'id' => '79',
'name' => 'a',
),
1 =>
array (
'id' => '79',
'name' => 'a',
),
2 =>
array (
'id' => '78',
'name' => 'b',
),
3 =>
array (
'id' => '36',
'name' => 'c',
),
);
foreach($ar as $k=>$f) {
foreach($ar as $p=>$t) if($k != $p && $f == $t) unset($ar[$k]);
}
print_r($ar);
Array
(
[1] => Array
(
[id] => 79
[name] => a
)
[2] => Array
(
[id] => 78
[name] => b
)
[3] => Array
(
[id] => 36
[name] => c
)
)
$arr=array(
0=>array(
'id'=>79,
'name'=>'a'
),
1=>array(
'id'=>79,
'name'=>'a'
),
2=>array(
'id'=>78,
'name'=>'b'
),
3=>array(
'id'=>36,
'name'=>'c'
),
);
$item=array();
foreach($arr as $k=>$v){
if(!isset($item[$v['id']])) $item[$v['id']]=$v;
}
print_r(array_values($item));
Array
(
[0] => Array
(
[id] => 79
[name] => a
)
[1] => Array
(
[id] => 78
[name] => b
)
[2] => Array
(
[id] => 36
[name] => c
)
)
$ar = array (
0 =>
array (
'id' => '79',
'name' => 'a',
),
1 =>
array (
'id' => '79',
'name' => 'a',
),
2 =>
array (
'id' => '78',
'name' => 'b',
),
3 =>
array (
'id' => '36',
'name' => 'c',
),
);
$temp =array();
$result =array();
foreach($ar as $item){
$temp[] = json_encode($item);
}
$temp = array_unique($temp);
foreach($temp as $item){
$result[] = json_decode($item,true);
}
var_dump($result);
array(3) {
[0]=>
array(2) {
["id"]=>
string(2) "79"
["name"]=>
string(1) "a"
}
[1]=>
array(2) {
["id"]=>
string(2) "78"
["name"]=>
string(1) "b"
}
[2]=>
array(2) {
["id"]=>
string(2) "36"
["name"]=>
string(1) "c"
}
}