您的位置:首页 > 编程语言 > PHP开发

php array_push 向数组增加值函数

2013-09-05 19:24 411 查看
php array_push 向数组增加值函数
public static function insert(&$array, $key, $newValue, $before = true) {
$result = false;
$size = sizeof($array);
for ($i=0; $i<$size; $i++) {
$value = array_shift($array);
if ($i==$key) {
if ($before) {
array_push($array, $newValue);
array_push($array, $value);
} else {
array_push($array, $value);
array_push($array, $newValue);
}
$result = true;
} else {
array_push($array, $value);
}
}
if (!$result) {
array_push($array, $newValue);
}
return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: