如何在PHP中合并两个关联数组

时间:2014-05-13 16:46:58

标签: php arrays array-merge

我一直在尝试合并两个关联数组。但我不知道PHP中是否可能。

第一个数组

  'images' => 
      0 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/iphone.png'
      1 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/1425328_405486846250283_806381377_o.jpg'
      2 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/bbg.jpg'
      3 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/gmail_bg.JPG'

第二个数组

'images' => 
      0 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/Capture.JPG'
      1 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bg.jpg'
      2 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/abc.JPG'
      3 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bg_dark.png'
      4 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bktile.png'

他们应该像这样合并在一起。

合并数组

  'images' => 
      0 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/iphone.png'
      1 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/1425328_405486846250283_806381377_o.jpg'
      2 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/bbg.jpg'
      3 => 
          'image_first' => string 'http://10.0.2.2/captcha-2/gmail_bg.JPG'
      4 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/Capture.JPG'
      5 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bg.jpg'
      6 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/abc.JPG'
      7 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bg_dark.png'
      8 => 
          'image_second' => string 'http://10.0.2.2/captcha-2/bktile.png'

怎么做?

1 个答案:

答案 0 :(得分:4)

array_merge()会做到这一点。 见http://de2.php.net/array_merge