将新行插入多维数组php


insert new row into multi-dimension array php

PHP:

如何将值插入多维数组中的特定行或在多维数组中插入空行?

发件人:

a ={ (0,1,2),
     (3,4,5),
     (6,7,8) }

成为

a ={ (0,1,2),
     (null,null,null),
     (3,4,5),
     (6,7,8) }

或者null为我想要的值?

在4warding dot com上使用gerry-03中的此函数应该是可能的:

function array_insert(&$input, $offset, $replacement){
    array_splice($input, $offset, 0, 0);
    $input[$offset] = $replacement;
}

演示:

$a = array(array(0, 1, 2), array(3, 4, 5), array(6, 7, 8));
array_insert($a, 1, array(9, 10, 11));

结果:

[0] => Array
    (
        [0] => 0
        [1] => 1
        [2] => 2
    )
[1] => Array
    (
        [0] => 9
        [1] => 10
        [2] => 11
    )
[2] => Array
    (
        [0] => 3
        [1] => 4
        [2] => 5
    )
[3] => Array
    (
        [0] => 6
        [1] => 7
        [2] => 8
    )