array_chunk(array,size,[preserve_keys])函数:把一个数组分割为新的数组块,preserve_keys是一个可选参数,其值是一个布尔值,意为是否保留原数组中元素的键值,若不保留则默认分配:
$array = array_chunk($array3,2,false);array_merge(array1,array2,[array3…])函数:合并多个数组,若合并的数组中存在相同的键,则最后一次出现的该键对应的值,会成为新数组中该键的值(任何数组中都不会存在同一个键名有两个值,后出现的值会覆盖前者)。
$array1 = array("姓名","性别","年龄","学历");$array2 = array("刘枫","男",26,"硕士");$array3 = array("型号","HTC","型号","Apple","型号","华为");$array = array_merge($array1,$array2,$array3);array_combine(array1,array2)函数:合并两个数组,前者成为新数组的键,后者成为新数组的值。
$array1 = array("姓名","性别","年龄","学历");$array2 = array("刘枫","男",26,"硕士");$array = array_combine($array1 , $array2);array_pop(array)函数:删除数组中的最后一个元素。
$array3 = array("型号","HTC","型号","Apple","型号","华为");$array = array_pop($array3);array_push(array,value1,[value2…])函数:向数组尾部插入一个或多个元素(适用于数值数组,或者是索引没有实质性意义的数组),无法指定键名。
$array3 = array("型号","HTC","型号","Apple","型号","华为");$array = array_push($array3,"型号","三星");其他函数可查找PHP手册或自行摸索。
实例 <?php//array()函数:创建数组$array1 = array("姓名","性别","年龄","学历");$array2 = array("刘枫","男",26,"硕士");$array3 = array("型号","HTC","型号","Apple","型号","华为");$array4 = array("语文"=>"A","数学"=>"A","英语"=>"A","物理"=>"A","化学"=>"A","生物"=>"B","地理"=>"C","历史"=>"B","政治"=>"D");$array5 = array("Lucifer","男",26,"硕士");echo "<br>数组1:";print_r($array1);echo "<br>数组2 :";print_r($array2);//array_chunk(array,size[,preserve_keys])函数:把一个数组分割为新的数组块,preserve_keys为是否保留原数组元素下标echo "<br>分割数组:";print_r(array_chunk($array3,2,false));//array_combine(array1,array2)函数:合并两个数组,一个作为键,一个作为值echo "<br>合并数组:";print_r(array_combine($array1 , $array2));//array_count_values(array)函数:统计数组中所有值出现的次数echo "<br>统计数组元素:";print_r(array_count_values($array4));//比较数组函数://array_diff():只比较键值//array_diff_assoc():比较键名和键值//array_diff_key():只比较键名。//可比较两个或多个数组,但返回差集为第一个数组之后的数组,分别与第一个数组比较差集的合集。echo "<br>比较数组:";print_r(array_diff_assoc($array2,$array5));//数组填充://array_fill(index,number,value):从index下标(索引)开始,为数组填充number个值为value的元素//array_fill_keys(keys,value):为指定索引key的元素,填充value,key可以是数组$array = array_fill(20,8,"成绩良好");echo "<br>数组填充:";print_r($array);运行结果: