-1

I have some array like that

[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 
        )

and then i have another array

[0] => Array (

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

)

[1] => Array (

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

)

but i want

[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 
        )

2
  • 1
    I think the most interesting question would be how did you create these 2 arrays. Maybe the best answer would be to look at that and see if you cannot create your desired array in one go rather than attempt to FIX it after they are built Commented May 14, 2016 at 14:16
  • Isn't this essentially the same problem as your previous question stackoverflow.com/questions/37224453/php-merger-array-object Commented May 14, 2016 at 15:20

1 Answer 1

0

Suppose $array1 contain your first array data you posted above.

$array2 contain your second array data you posted above

<?php 
$cnt = 0;
foreach($array1 as $key => $arr1) {
  $array1[$key]['alt'] = $array2[$cnt]['alt'];
  $array1[$key]['caption'] = $array2[$cnt]['caption'];
  $cnt++;
} 
?>
Sign up to request clarification or add additional context in comments.

1 Comment

This will work, but only if you have BOTH arrays in the same order and BOTH arrays of the same size

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.