search

Home  >  Q&A  >  body text

How to recombine two-dimensional arrays

$a = array(0=>'',1=>arrray(0=>1,1=>2),2=>'',3=>arrray(0=> ;1,1=>2));

How can I turn this two-dimensional array into the following one-dimensional array:

$a = array(

0= >'',

1=>'1,2',

2=>'',

3=>'1,2',

};

亮1152 days ago1211

reply all(4)I'll reply

  • 亮

    2021-09-30 21:17:08

    It has been verified that it works. I have the same idea, but I am stuck. Thank you for the guidance.

    reply
    0
  • autoload

    autoload2021-09-30 14:26:27

    First of all, there is a problem with your array. What is arrray? Although I don’t know why I wrote it like this, it’s okay if I just force it outimage.png

    reply
    2
  • 淡然

    The second foreach is redundant foreach($a as $k=>$v){ if(is_array($v)){ $a[$k] = implode(",",$v); } }

    淡然 · 2021-10-04 14:14:19
    autoload

    Functions are used less, that’s true

    autoload · 2021-10-08 09:05:00
  • Cancelreply