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

问题描述 投票:-5回答:1

我一直在尝试合并两个关联数组。但我不知道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'

怎么做?

php arrays array-merge
1个回答
4
投票

array_merge()将成功。见http://de2.php.net/array_merge

© www.soinside.com 2019 - 2024. All rights reserved.