在Key Array PHP填充值

时间:2016-05-14 13:56:19

标签: php arrays

我有一些像那样的数组


[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 个答案:

答案 0 :(得分:0)

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

$ array2包含您在上面发布的第二个数组数据

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