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;
}
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;
}
相关文章推荐
- php array_push()数组函数:将一个或多个单元压入数组的末尾(入栈)
- php array_push()数组函数:将一个或多个单元压入数组的末尾(入栈)
- PHP array_push 数组函数
- PHP array_push() 函数 向数组末尾追加元素
- PHP array_push 数组函数
- PHP array_walk_recursive 使用自定的函数处理数组中的每一个元素
- JavaScript数组函数unshift、shift、pop、push使用实例
- PHP array_key_exists() 函数(判断某个数组中是否存在指定的 key)
- 数组通过array_push函数进行排序 及 选择排序
- PHP array_splice函数实现数组任意位置插入
- php array_walk_recursive 使用自定的函数处理数组中的每一个元素
- (转载)PHP array_push() 函数
- php通过array_push()函数添加多个变量到数组末尾的方法
- JavaScript 数组操作函数总结(push,pop,join,shift,unshift,slice,splice,concat)
- php array_map使用自定义的函数处理数组中的每个值
- php array_map()数组函数使用说明
- JavaScript数组函数unshift、shift、pop、push使用实例
- JavaScript数组函数unshift、shift、pop、push使用实例
- JavaScript 数组操作函数总结(push,pop,join,shift,unshift,slice,splice,concat)
- js往数组中添加值用push()函数