Home  >  Q&A  >  body text

Multi-dimensional array traversal, please give me an answer? ? ?

$ Result = Array (
Array (
'name' = & gt; 'network',
'phone' = & gt #'The 1st'=>'Program Test 1',
          'The 2nd'=>'Program Test 2',
          ),
          array(
              'name'=>'Network 1',
          'Telephone'=>'12345678911',
 &

小帅小帅1838 days ago1069

reply all(3)I'll reply

  • 海风

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

    The following program can get the array you want to merge no matter how the $result key name is changed:

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

    %

    reply
    0
  • 移动用户-6569216

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

    I can't help you read it because your writing is unclear.

    reply
    1
  • 小帅

    Thank you, I've got it now, like this: $result2=array(); foreach($result as $k=>$v){ $result2[$k]['name'] = $v['name']; $result2[$k]['Phone'] = $v['Phone']; foreach($v['answer'] as $ak=>$av){ $result2[$k][$av['question_id']] = $av['answer']; } }

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