? ? ? ?$result=array(
? ? ? ? ? ?array(
? ? ? ? ? ? ? ?'name'=>'網絡',
? ? ? ? ? ? ? ?'電話'=>'12345678910',
? ? ? ? ? ? ? ?'answer'=>
? ? ? ? ? ? ? ? ? ?array(
? ? ? ? ? ? ? ? ? ?'question_id'=>'第1',
? ? ? ? ? ? ? ? ? ?'answer'=>'程序測試1',
? ? ? ? ? ? ? ? ? ? ? ?),
? ? ? ? ? ? ? ? ? ?array(
? ? ? ? ? ? ? ? ? ? ? ?'question_id'=>'第2',
? ? ? ? ? ? ? ? ? ? ? ?'answer'=>'程序測試2',
? ? ? ? ? ? ? ? ? ?)
? ? ? ? ? ?),
? ? ? ? ? ?array(
? ? ? ? ? ? ? ?'name'=>'網絡1',
? ? ? ? ? ? ? ?'電話'=>'12345678911',
? ? ? ? ? ? ? ?'answer'=>
? ? ? ? ? ? ? ? ? ?array(
? ? ? ? ? ? ? ? ? ? ? ?'question_id'=>'第3',
? ? ? ? ? ? ? ? ? ? ? ?'answer'=>'程序測試3',
? ? ? ? ? ? ? ? ? ?),
? ? ? ? ? ? ? ?array(
? ? ? ? ? ? ? ? ? ?'question_id'=>'第4',
? ? ? ? ? ? ? ? ? ?'answer'=>'程序測試4',
? ? ? ? ? ? ? ?)
? ? ? ? ? ?)
? ? ? ?);
// ? ? ? ?將上邊數(shù)組遍歷成下邊數(shù)組,求大佬。。
? ? ? ?$result2=array(
? ? ? ? ? ?array(
? ? ? ? ? ? ? ?'name'=>'網絡',
? ? ? ? ? ? ? ?'電話'=>'12345678910',
? ? ? ? ? ? ? ?'第1'=>'程序測試1',
? ? ? ? ? ? ? ?'第2'=>'程序測試2',
? ? ? ? ? ?),
? ? ? ? ? ?array(
? ? ? ? ? ? ? ?'name'=>'網絡1',
? ? ? ? ? ? ? ?'電話'=>'12345678911',
? ? ? ? ? ? ? ?'第3'=>'程序測試3',
? ? ? ? ? ? ? ?'第4'=>'程序測試4',
? ? ? ? ? ?)
? ? ? ?);
以下程序不管$result鍵名怎么改都能得到你想要合并的數(shù)組:
$arr = [];
? ? foreach ($result as $k => $v){
foreach ($result[$k] as $k1 =>$v2){
if (is_array($result[$k][$k1])){
foreach ($result[$k][$k1] as $k2 => $v2){
$arr[] = $v2;
}
$temp = [$arr[0] => $arr[1]];
unset ($result[$k][$k1]);
unset ($arr);
$result[$k] = array_merge($result[$k],$temp);
unset($temp);
}
}
? ? }
你這個寫得不清不楚的我沒法幫你看