2016-05-14 54 views
-1

我有一些阵像填充值在按键行列PHP

 

[11] => Array 
     (
      [hotlink_thumb] => http://t2.gstatic.com/images?q=tbn:ANd9GcQHzF0iX9-f-P6BBDriiPKNMLYFAsikzPIbAWL0eZLH14ujpZkv 
      [hotlink_source] => http://homeoidal.pro/wp-content/uploads/2015/05/outdoor-furniture-interesting-diy-outdoor-furniture-design-featuring-natural-brown-wicker-rattan-sectional-sofa-with-brown-padded-seat-cushion-and-cool-grey-pillow-plus-brown-rectangle-striped-plank.jpg 
      [alt] => 
      [caption] => 
      [description] => 
      [href] => http://localhost/wordpress/homemade-patio-furniture/furniture-tv-media/ 
      [src] => 
      [title] => Furniture Tv Media 
     ) 

    [12] => Array 
     (
      [hotlink_thumb] => http://t1.gstatic.com/images?q=tbn:ANd9GcTtYn0sWBKe8XIWgvmg7IBcNCB63oSwPEVGxKc6b5w8z3DPSRV_IA 
      [hotlink_source] => http://www.widmeyer-construction.com/wp-content/uploads/2012/09/Redwood-Benches-005.jpg 
      [alt] => 
      [caption] => 
      [description] => 
      [href] => http://localhost/wordpress/homemade-patio-furniture/furniture-tv-deals/ 
      [src] => 
      [title] => Furniture Tv Deals 
     ) 

,然后我有另一个数组

 
[0] => Array (

[alt] => the alt one 
[caption] => the caption one 

) 

[1] => Array (

[alt] => the alt two 
[caption] => the caption two 

) 

,但我想

 

[11] => Array 
     (
      [hotlink_thumb] => http://t2.gstatic.com/images?q=tbn:ANd9GcQHzF0iX9-f-P6BBDriiPKNMLYFAsikzPIbAWL0eZLH14ujpZkv 
      [hotlink_source] => http://homeoidal.pro/wp-content/uploads/2015/05/outdoor-furniture-interesting-diy-outdoor-furniture-design-featuring-natural-brown-wicker-rattan-sectional-sofa-with-brown-padded-seat-cushion-and-cool-grey-pillow-plus-brown-rectangle-striped-plank.jpg 
      [alt] => the alt two 
      [caption] => the caption one 
      [description] => 
      [href] => http://localhost/wordpress/homemade-patio-furniture/furniture-tv-media/ 
      [src] => 
      [title] => Furniture Tv Media 
     ) 

    [12] => Array 
     (
      [hotlink_thumb] => http://t1.gstatic.com/images?q=tbn:ANd9GcTtYn0sWBKe8XIWgvmg7IBcNCB63oSwPEVGxKc6b5w8z3DPSRV_IA 
      [hotlink_source] => http://www.widmeyer-construction.com/wp-content/uploads/2012/09/Redwood-Benches-005.jpg 
      [alt] => the alt two 
      [caption] => the caption two 
      [description] => 
      [href] => http://localhost/wordpress/homemade-patio-furniture/furniture-tv-deals/ 
      [src] => 
      [title] => Furniture Tv Deals 
     ) 

+1

贴我觉得最有趣的问题是你如何创建这些2个阵列的第二阵列的数据。也许最好的答案是看看,看看你是否不能一次性创建你想要的数组,而不是试图在构建它们之后修复它 – RiggsFolly

+0

这不是和你以前的问题基本相同的问题http:// stackoverflow .com/questions/37224453/php-merger-array-object – Barmar

回答

0

假设$ array1中包含您的你上面发布的第一个数组数据。

$数组2包含您在上面

<?php 
$cnt = 0; 
foreach($array1 as $key => $arr1) { 
    $array1[$key]['alt'] = $array2[$cnt]['alt']; 
    $array1[$key]['caption'] = $array2[$cnt]['caption']; 
    $cnt++; 
} 
?> 
+0

这将会起作用,但前提是两个数组的大小相同并且数组大小相同 – RiggsFolly