1、array_diff_assoc($arr1,$arr2,$arr3...) 函数:比较两个数组的键名和键值,并返回差集
例:
<?php
$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");
$a2=array("1"=>"this_1","2"=>"this_2","3"=>"this_3");
$result1 = array_diff_assoc($a1,$a2); //数组可以交换顺序滴,也可以是多个数组
var_dump($result1);
?>
打印结果:
array (size=2)
4 => string 'this_4' (length=6)
5 => string 'this_5' (length=6)
2、array_keys() 函数:返回包含数组中所有键名的一个新数组
例:
<?php
$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");
$result2 = array_keys($a1);
var_dump($result2);
?>
打印结果:
array (size=4)
0 => int 2
1 => int 3
2 => int 4
3 => int 5
3、array_key_exists() 函数:检查某个数组中是否存在指定的键名,如果键名存在则返回 true,如果键名不存在则返回 false。
例:
<?php
$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");
if (key_exists("2",$a1)){
echo "yes!";
}else{
echo "no!";
}
?>
输出结果:
yes!
4、sort() 函数:以升序对数组排序
5、rsort() 函数:以降序对数组排序
6、asort() 函数:根据值,以升序对关联数组进行排序
7、ksort() 函数:根据键,以升序对关联数组进行排序
8、arsort() 函数:根据值,以降序对关联数组进行排序
9、krsort() 函数:根据键,以降序对关联数组进行排序
10、count() 函数:返回数组中元素的数目
例:
<?php
$a1=array("2"=>"this_2","3"=>"this_3","4"=>"this_4","5"=>"this_5");
$result3 = count($a1);
echo $result3;
?>
输出结果:
4