Rumah > Artikel > pembangunan bahagian belakang > php 的数组合并问题怎么解决
<code>array(3) { [0] => array(2) { ["path"] => string(3) "111" ["title"] => string(35) "问题1" } [1] => array(2) { ["path"] => string(3) "222" ["title"] => string(35) "问题1" } [2] => array(2) { ["path"] => string(4) "5555" ["title"] => string(12) "问题2" } } </code>
怎么让他变成下面的这种格式
<code>array(2) { [0] => array(3) { ["title"] => string(35) "问题1" ["path"] => array(2) { [0]=> string(4) "111" [1] => string(4) "222" } } [1] => &array(3) { ["title"] => string(12) "问题2" ["id"] => string(1) "2" ["path"] => array(1) { [0] => string(4) "5555" } } } </code>
就是title相同的合并,path组成一个数组,以此类推
<code>array(3) { [0] => array(2) { ["path"] => string(3) "111" ["title"] => string(35) "问题1" } [1] => array(2) { ["path"] => string(3) "222" ["title"] => string(35) "问题1" } [2] => array(2) { ["path"] => string(4) "5555" ["title"] => string(12) "问题2" } } </code>
怎么让他变成下面的这种格式
<code>array(2) { [0] => array(3) { ["title"] => string(35) "问题1" ["path"] => array(2) { [0]=> string(4) "111" [1] => string(4) "222" } } [1] => &array(3) { ["title"] => string(12) "问题2" ["id"] => string(1) "2" ["path"] => array(1) { [0] => string(4) "5555" } } } </code>
就是title相同的合并,path组成一个数组,以此类推
array_merge