string(3) "111" ["title"] => string(35) "问题1" } [1] => array(2) { [">
当前位置:Gxlcms > PHP教程 > php的数组合并问题怎么解决

php的数组合并问题怎么解决

时间:2021-07-01 10:21:17 帮助过:6人阅读

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

人气教程排行