日期:2014-05-17 浏览次数:20630 次
$arr1=array(
0=>array('pid'=>1,name=>'user1'),
1=>array('pid'=>2,name=>'user2')
);
$arr2=array(
0=>array('pid'=>3,name=>'user1'),
1=>array('pid'=>4,name=>'user4')
);
$arr2=array(
0=>array('pid'=>1,name=>'user1'),
1=>array('pid'=>2,name=>'user2')
2=>array('pid'=>3,name=>'user3'),
3=>array('pid'=>4,name=>'user4')
);
$arr1=array(
0=>array('pid'=>1,'name'=>'user1'),
1=>array('pid'=>2,'name'=>'user2')
);
$arr2=array(
0=>array('pid'=>3,'name'=>'user1'),
1=>array('pid'=>4,'name'=>'user4')
);
$t = array();
foreach(array_merge($arr1, $arr2) as $v) {
if(isset($t[$v['name']])) {
if($t[$v['name']]['pid'] > $v['pid']) $t[$v['name']]['name'] = "user{$v['pid']}";
else $v['name'] = "user{$v['pid']}";
}
$t[$v['name']] = $v;
}
print_r($t);
Array
(
[user1] => Array
(
[pid] => 1
[name] => user1
)
[user2] => Array
(
[pid] => 2
[name] => user2