Last active
December 16, 2015 16:40
-
-
Save panfeng/5465156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pre_print_r($var){ | |
echo "<pre>"; | |
print_r($var); | |
echo "</pre>"; | |
echo "<br />"; | |
} | |
/* | |
http://www.w3school.com.cn/php/func_array_splice.asp | |
array_splice与array_slice函数类似,选择数组中的一系列元素,但不返回,而是删除它们并用其它值代替。 | |
如果提供了第四个参数,则之前选中的那些元素将被第四个参数指定的数组取代。 最后生成的数组将会返回。 | |
* array_splice(array,offset,length,array) | |
* array 必需。规定数组。 | |
* offset 必需。数值。如果 offset 为正,则从输入数组中该值指定的偏移量开始移除。如果 offset 为负,则从输入数组末尾倒数该值指定的偏移量开始移除。 | |
* length 可选。数值。如果省略该参数,则移除数组中从 offset 到 结尾的所有部分。如果指定了 length 并且为正值,则移除这么多元素。如果指定了 length 且为负值,则移除从 offset 到数组末尾倒数 length 为止中间所有的元素。 | |
* array 被移除的元素由此数组中的元素替代。如果没有移除任何值,则此数组中的元素将插入到指定位置 | |
* | |
* */ | |
$a1=array("Dog","Cat","Horse","Bird"); | |
$a2=array("Tiger","Lion"); | |
//pre_print_r(array_splice($a1,0,0,$a2)); | |
//pre_print_r(array_splice($a1,0,2,$a2)); | |
pre_print_r(array_splice($a1,0,2,$a2)); | |
//返回被删除的值 此时输出为 | |
/* | |
Array | |
( | |
[0] => Dog | |
[1] => Cat | |
) | |
*/ | |
pre_print_r($a1); | |
/* | |
Array | |
( | |
[0] => Tiger | |
[1] => Lion | |
[2] => Horse | |
[3] => Bird | |
) | |
*/ | |
//array_splice($a1,0,2,$a2); | |
//pre_print_r($a1); | |
/* | |
Array | |
( | |
[0] => Tiger | |
[1] => Lion | |
[2] => Dog | |
[3] => Cat | |
[4] => Horse | |
[5] => Bird | |
) | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment