2016-05-14 74 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