Heim  >  Artikel  >  Backend-Entwicklung  >  php多维数组内部合并

php多维数组内部合并

WBOY
WBOYOriginal
2016-06-06 20:35:55997Durchsuche

<code>array(3) {
  [0] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "2"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(44)
  }
  [1] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "3"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(66)
  }
  [3] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "2"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(44)
  }
}
</code>

请问如何把一样的一维数组合并
并且如果两者一样 把 [2] => string(1) "2"的值相加后的值作为新的值.键不变

回复内容:

<code>array(3) {
  [0] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "2"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(44)
  }
  [1] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "3"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(66)
  }
  [3] => array(9) {
    [0] => string(1) "1"
    [1] => string(3) "175"
    [2] => string(1) "2"
    [3] => string(2) "22"
    [4] => string(2) "22"
    [5] => string(2) "-1"
    [6] => string(1) "0"
    [7] => string(11) "小份+0元"
    [8] => int(44)
  }
}
</code>

请问如何把一样的一维数组合并
并且如果两者一样 把 [2] => string(1) "2"的值相加后的值作为新的值.键不变

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn