Home  >  Article  >  Backend Development  >  php 的数组合并问题怎么解决

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

WBOY
WBOYOriginal
2016-06-06 20:37:39897browse

<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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn