php 把一个一维数组的值依次赋值到二维数组中的每一项

Array
(

[0] => 1
[1] => 4
[2] => 2
[3] => 6

)

 

Array
(

[0] => Array
    (
        [field_name] => 镇政府
        [field_id] => d14
        [create_time] => 1490235566
    )

[1] => Array
    (
        [field_name] => 小邢
        [field_id] => d13
        [create_time] => 1490235525
    )

[2] => Array
    (
        [field_name] => 这是场地
        [field_id] => d12
        [create_time] => 1490235386
    )

[3] => Array
    (
        [field_name] => 村南
        [field_id] => d11
        [create_time] => 1489734050
    )

)

希望能把最上面那个一维数组对应的添加到二维数组里,两个数组的key名相同

需要这样的结果:

Array
(

[0] => Array
    (
        [field_name] => 镇政府
        [field_id] => d14
        [create_time] => 1490235566
        [number]=>1
    )

[1] => Array
    (
        [field_name] => 小邢
        [field_id] => d13
        [create_time] => 1490235525
        [number]=>4
    )

[2] => Array
    (
        [field_name] => 这是场地
        [field_id] => d12
        [create_time] => 1490235386
        [number]=>2
    )

[3] => Array
    (
        [field_name] => 村南
        [field_id] => d11
        [create_time] => 1489734050
        [number]=>6
    )

)

办法:

foreach($data2 as $key=> &$item)
{
    $item['number'] = $data1[$key];
}
posted @ 2018-03-29 10:07  御世制人  阅读(860)  评论(0编辑  收藏  举报