2016-05-14 9 views
-1

Ich habe einige Array wie dieFill Wert Bei Key Array 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 
     ) 

und ich habe dann ein anderes Array

 
[0] => Array (

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

) 

[1] => Array (

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

) 

aber ich will

 

[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

Ich denke, die interessanteste Frage wäre, wie Sie diese 2-Arrays erstellt haben. Vielleicht wäre die beste Antwort, sich das anzuschauen und zu sehen, ob Sie das gewünschte Array nicht auf einmal erstellen können, anstatt es zu reparieren, nachdem sie erstellt wurden – RiggsFolly

+0

Ist das nicht im Wesentlichen das gleiche Problem wie Ihre vorherige Frage http: // stackoverflow .com/questions/37224453/php-merger-array-object – Barmar

Antwort

0

Angenommen $ array1 enthalten Ihre erste Array-Daten, die Sie oben gepostet haben.

$ array2 enthalten Ihre zweite Array-Daten Sie über

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

Dies funktioniert, aber nur, wenn Sie BOTH-Arrays in der gleichen Reihenfolge und BOTH-Arrays der gleichen Größe haben – RiggsFolly