编程语言
首页 > 编程语言> > php 把一个一维数组的值依次赋值到二维数组中的每一项

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];
}

标签:name,create,id,field,数组,time,Array,php,每一项
来源: https://blog.51cto.com/u_13481146/2818248