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 值我想引入?
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
)