PHP Merger数组对象


PHP Merger Array Object

我对如何合并这个数组有一些问题。能帮我吗?

第一个阵列:

大堆([22]=>WP_Post对象([ID]=>22[post_author]=>1)[23]=>WP_Post对象([ID]=>23[post_author]=>1))

第二个阵列:

大堆([0]=>stdClass对象([img_tumb]=>small_duck.jpg[img_full]=>duck.jpg)[1] =>stdClass对象([img_tumb]=>small_fish.jpg[img_full]=>fish.jpg))

应该输出:

大堆([22]=>WP_Post对象([ID]=>22[post_author]=>1[img_tumb]=>small_duck.jpg[img_full]=>duck.jpg)[23]=>WP_Post对象([ID]=>23[post_author]=>1[img_tumb]=>small_fish.jpg[img_full]=>fish.jpg))

数组键跟在第一个数组后面,

这很有效。。。

$first = array(
    22 => array(
        'ID' => 22,
        'post_author' => 1
    ),
    23 => array(
        'ID' => 23,
        'post_author' => 1
    )
);
$second  = array(
    array(
        'img_thumb' => 'small_duck.jpg',
        'img_full' => 'duck.jpg'
    ),
    array(
        'img_thumb' => 'small_fish.jpg',
        'img_full' => 'fish.jpg'
    )
);
echo '<pre>';
var_dump($first);
var_dump($second);
$i=0;
$should = array();
foreach ($first as $key => $arr) {
    if(isset($second[$i]))
        $arr = array_merge($arr,$second[$i]);
    $should[$key] = $arr;
    $i++;
}
var_dump($should);