suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Mehrdimensionale Array-Durchquerung, bitte geben Sie mir eine Antwort? ? ?

        $result=array(
                                                                                                                                                                                                                                                                                                                      ,
                                                                                                                                                                                                                                  'Programmtest 1' 'question_id'=>'Programmtest 2',
. ),
                                                                                                               t, Äh. 'Antwort ' = & GT; 'Programmtest 3',
),
Array ;
// Überquere das obere Array in das untere Array, bitte hilf mir. . L $ result2 = Array (
Array (
'Name' = & gt; 'Netzwerk',
'Telefon' = & gt; '12345678910',

'Der 1.'=>'Programmtest 1',
            'Der 2.'=>'Programmtest 2',
              ),
              array(
                  'name'=>' Netzwerk 1',
                'Telefon'= & gt; '12345678911',
'3' = & gt; 'Programmtest 4',
); ;

小帅小帅1882 Tage vor1100

Antworte allen(3)Ich werde antworten

  • 海风

    海风2019-10-09 10:10:24

    以下程序不管$result键名怎么改都能得到你想要合并的数组:

    $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);

    }

    }

        }


    Antwort
    0
  • 移动用户-6569216

    移动用户-65692162019-10-08 16:52:56

    你这个写得不清不楚的我没法帮你看

    Antwort
    1
  • 小帅

    谢谢你,我现在搞定了,是这样的: $result2=array(); foreach($result as $k=>$v){ $result2[$k]['name'] = $v['name']; $result2[$k]['电话'] = $v['电话']; foreach($v['answer'] as $ak=>$av){ $result2[$k][$av['question_id']] = $av['answer']; } }

    小帅 · 2019-10-08 16:57:23
  • StornierenAntwort