php 推送到数组的特定位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9296116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:30:28  来源:igfitidea点击:

push to specific position of array

phparrays

提问by mrdaliri

Possible Duplicate:
Insert into array at a specified place

可能的重复:
在指定位置插入数组

How to push 1 or more values to middle (or a specific position/index) of an array? for example:

如何将 1 个或多个值推送到数组的中间(或特定位置/索引)?例如:

$a = array('a', 'b', 'e', 'f');
array_pushTo($a, 1, 'c', 'd'); // that function i'm looking for. first parameter is the array, second is the index, and third and other are the values.
// $a now is: array('a', 'b', 'c', 'd', 'e', 'f');

回答by KARASZI István

array_spliceis probably what you're looking for:

array_splice可能是你要找的:

array_splice($a, 1, 0, array('c', 'd'));