php结合/合并多维数组

时间:2013-06-05 11:56:35

标签: php arrays merge multidimensional-array

您好我会以这种方式合并/组合两个多维数组: - 结果数组与第一个数组具有相同的维度 - 如果数组2的元素'IdCar'和'NameCar'与第一个元素的某个元素匹配,我必须在第一个数组中添加Color ...

数组1:

array (size=2)
  0 => 
    array (size=2)
      'IdCar' => 
        array (size=2)
          0 => string '34' 
          1 => string '35' 
      'NameCar' => 
        array (size=2)
          0 => string 'Young' 
          1 => string 'Senior'
  1 => 
    array (size=2)
      'IdCar' => 
        array (size=2)
          0 => string '134' 
          1 => string '135' 
      'NameCar' => 
        array (size=2)
          0 => string 'Large' 
          1 => string 'Small'

,第二个是:

array (size=3)
  0 => 
    array (size=3)
      'IdCar' => 
        array (size=2)
          0 => string '34' 
          1 => string '35' 
      'NameCar' => 
        array (size=2)
          0 => string 'Young' 
          1 => string 'Senior'
      'Color' => 
        array (size=2)
          0 =>
           array (size=1)
              0 => string 'Yellow' 
          1 =>
           array (size=1)
              0 => string 'Green' 




 1 => 
    array (size=3)
      'IdCar' => 
        array (size=2)
          0 => string '34' 
          1 => string '35' 
      'NameCar' => 
        array (size=2)
          0 => string 'Young' 
          1 => string 'Senior'
      'Color' => 
        array (size=2)
          0 =>
           array (size=1)
              0 => string 'Red' 
          1 =>
           array (size=1)
              0 => string 'Black' 

 2 => 
     array (size=2)
      'IdCar' => 
        array (size=2)
          0 => string '134' 
          1 => string '135' 
      'NameCar' => 
        array (size=2)
          0 => string 'Large' 
          1 => string 'Small'
      'Color' => 
        array (size=2)
          0 =>
           array (size=1)
              0 => string 'Pink' 
          1 =>
           array (size=1)
              0 => string 'White' 

我希望得到一个结果数组,其大小与第一个相同:

array (size=2)
  0 => 
    array (size=2)
      'IdCar' => 
        array (size=2)
          0 => string '34' 
          1 => string '35' 
      'NameCar' => 
        array (size=2)
          0 => string 'Young' 
          1 => string 'Senior'
      'Color' => 
        array (size=2)
          0 =>
           array (size=2)
              0 => string 'Yellow' 
              1 => string 'Red' 
          1 =>
           array (size=2)
              0 => string 'Green' 
              1 => string 'Black' 
  1 => 
    array (size=2)
      'IdCar' => 
        array (size=2)
          0 => string '134' 
          1 => string '135' 
      'NameCar' => 
        array (size=2)
          0 => string 'Large' 
          1 => string 'Small'
      'Color' => 
        array (size=2)
          0 =>
           array (size=2)
              0 => string 'Pink' 
          1 =>
           array (size=2)
              0 => string 'White' 

谢谢

0 个答案:

没有答案