我想转换或重新排列这个php数组:
$contacts = array(
array(
"name" => "Peter Parker",
"email" => "peterparker@mail.com",
),
array(
"name" => "Peter Parker",
"email" => "petermail2@mail.com",
),
array(
"name" => "Harry Potter",
"email" => "harrypotter@mail.com",
)
);
到:
$contacts ["Peter Parker"] = {"peterparker@mail.com", "petermail2@mail.com" } ;
$contacts ["Harry Potter"] = {"harrypotter@mail.com"} ;
表示在新数组或行中组装或合并具有相同名称的条目。
答案 0 :(得分:0)
foreach( $contacts as $record ){
$newcontacts[$record['name']][] = $record['email'];
}