PHP Merger Array Object

前端 未结 1 1304
感情败类
感情败类 2021-01-23 07:49

i have some problem how merger this array. could help me ?

First array :

Array
    (
        [22] => WP_Post Object
            (
                   


        
相关标签:
1条回答
  • 2021-01-23 08:05

    This works...

    $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);
    
    0 讨论(0)
提交回复
热议问题