我正在尝试将一个数组作为第一个元素插入到多维数组中。我的原始数组示例
Array (
0 => array ( "point1.0" => "some data", "point2.0" => "some data" )
1 => array ( "point1.1" => "some data", "point2.1" => "some data" )
)
然后我有要插入的数组作为第一个元素
$newArray = array("point1.2" => "some data", "point2.2" => "some data" )
我的结果应该是
Array (
0 => array ( "point1.2" => "some data", "point2.2" => "some data" )
1 => array ( "point1.0" => "some data", "point2.0" => "some data" )
2 => array ( "point1.1" => "some data", "point2.1" => "some data" )
)
在这种情况下,array_unshift 似乎失败了。有没有比创建一个新数组并通过 foreach 循环插入每个子数组更好的解决方案?