Traversal tatasusunan berbilang dimensi, tolong beri saya jawapan? ? ?
小帅
小帅 2019-10-08 14:34:22
0
3
1103

        $result=array(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           , 1',
                                                                                                                                                                                                                                                                                                                                                                                                                                'Ujian Program 1' 'id_soalan'=>' Ujian Program 2',                                                                                                                                                                                                                                                                         GT; 'Ujian Program 3',
),
Tatasusunan ;
// Lintas tatasusunan atas ke dalam tatasusunan bawah, tolong bantu saya. . L $ hasil2 = Tatasusunan (
tatasusunan (
'nama' = & gt; 'rangkaian',
'telefon' = & gt; '12345678910',

'Yang pertama'=>'Ujian Program 1',
            'Yang ke-2'=>'Ujian Program 2',
              ),
                                                                      t;'Rangkaian 1',
                'Telefon'= & gt; '12345678911',
'3' = & gt; ;

小帅
小帅

membalas semua(2)
海风

Atur cara berikut boleh mendapatkan tatasusunan yang ingin anda cantumkan tidak kira bagaimana nama kunci $result ditukar:

$arr = [];

foreach ($result as $k => $v){

foreach ($hasil [$k] sebagai $k1 =>$v2){

jika (is_array($result[$k][$k1])){

foreach ($result[$k][$k1] sebagai $k2 => $v2){

$arr[] = $v2;

}

$temp = [$arr[0] => $arr[1]];

tidak ditetapkan ($hasil [$k ][$k1]);

unset ($arr);

$result[$k] = array_merge($result[$k],$temp);

unset($temp);

}

}

}


移动用户-6569216

Saya tidak dapat membantu anda membacanya kerana tulisan anda tidak jelas.

  • balas Terima kasih, saya telah mendapatnya sekarang, seperti ini: $result2=array(); foreach($hasil sebagai $k =>$v){ $result2[$k]['name'] = $v['name']; $result2[$k]['Telefon'] = $v['Telefon']; foreach($v['jawapan'] sebagai $ak=>$av){ $result2[$k][$av['question_id']] = $av['jawapan']; } }
    小帅 pengarang 2019-10-08 16:57:23
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan