php 的数组合并问题怎么解决
程序员文章站
2023-12-31 12:51:04
...
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"
}
}
怎么让他变成下面的这种格式
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"
}
}
}
就是title相同的合并,path组成一个数组,以此类推
回复内容:
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"
}
}
怎么让他变成下面的这种格式
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"
}
}
}
就是title相同的合并,path组成一个数组,以此类推
array_merge