$laArray = array(
0 => array("id"=>11,"name"=>"happy","age"=>"20","moeny"=>100),
1 => array("id"=>29,"name"=>"lucy","age"=>"20","moeny"=>100),
2 => array("id"=>34,"name"=>"happy","age"=>"20","moeny"=>235),
3 => array("id"=>42,"name"=>"happy","age"=>"15","moeny"=>100),
4 => array("id"=>51,"name"=>"happy","age"=>"20","moeny"=>600),
5 => array("id"=>61,"name"=>"lucy","age"=>"20","moeny"=>350),
6 => array("id"=>61,"name"=>"lucy","age"=>"23","moeny"=>150),
);
$temArr = $laArray ;
$newArr = array();
foreach($laArray as $num => $arr ){
unset($temArr[$num]);
$id = $arr['id'];
foreach($temArr as $tNum =>$tArr ){
$n_arr = array();
$tem_moeny = array();
if($arr['name']== $tArr['name'] && $arr['age']== $tArr['age']){
$id .= '+'.$tArr['id'];
$n_arr['id'] = $id;
$n_arr['name'] = $arr['name'];
$n_arr['age'] = $arr['age'];
if(is_array($arr['moeny'])){
array_push($n_arr['moeny'], $tArr['moeny']);
}else{
$tem_moeny [] = $arr['moeny'];
$tem_moeny [] = $tArr['moeny'];
}
$tem_moeny[] = $tArr['moeny'];
$n_arr['moeny'] = $tem_moeny;
$newArr[] = $n_arr ;
}
}
if($id == $arr['id']){
$newArr[] = $arr ;
}
}
print_r($newArr);
?>
$tmpArray = array();
foreach ($laArray as $row) {
$key = $row['name'] . $row['age'];
if (array_key_exists($key, $tmpArray)) {
$tmpArray[$key]['id'] = $tmpArray[$key]['id'] . '+' . $row['id'];
if (is_array($tmpArray[$key]['moeny'])) {
$tmpArray[$key]['moeny'][] = $row['moeny'];
} else {
$tmpArray[$key]['moeny'] = array($tmpArray[$key]['moeny'], $row['moeny']);
}
} else {
$tmpArray[$key] = $row;
}
}
echo "
";
var_dump($tmpArray);