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

WBOY
Release: 2016-06-06 20:37:39
Original
935 people have browsed it

<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>
Copy after login
Copy after login

怎么让他变成下面的这种格式

<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>
Copy after login
Copy after login

就是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>
Copy after login
Copy after login

怎么让他变成下面的这种格式

<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>
Copy after login
Copy after login

就是title相同的合并,path组成一个数组,以此类推

array_merge

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template