1、合并数组

 array_merge函数将数组合并到一起,返回一个联合的数组。所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次追加。其形式为:

   array merge(array arrayl, array array2[, array arrayN])

如果输入数组包含的某个键在结果数组中已经存在,那么该键/值对将覆盖前面已经存在的元素。

<?php
 $class1=array("John"=>100, "James"->85);
 $class2=array("Micky"=>78,"John"=>45):
 $classScores= array_merge($class1,$class2);
 print_r($classScores);
?>

运行以上程序,效果如下所示:

 Array ([John] =>45 [James] =>85 [Micky]=>78

拆分数组的两个函数:
1.array_slice()
携带三个参数,参数一为目标数组,参数二为offset,参数三为length。作用为,从目标数组中取出从offset开始长度为length的子数组。
如果offset为正数,则开始位置从数组开头查offset处,如果offset为负数开始位置从距数组末尾查offset处。如果length为正数,则毫无疑问取出的子数组元素个数为length,如果length为负数,则子数组从offset开始到距数组开头count(目标数组)-|length|处结束。特殊地,如果length为空,则结束位置在数组结尾。
例子:

<?php
$input = array("a", "b", "c", "d", "e");
$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"
// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>

上例将输出:

Array
(
    [0] => c
    [1] => d
)
Array
(
    [2] => c
    [3] => d
)

2.array_splice()
携带三个参数,同上,作用是删除从offset开始长度为length的子数组。
例子:

<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")

$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green",
// "blue", "black", "maroon")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green",
// "blue", "purple", "yellow");
?>