1、array_count_values(计算某个字符用了多少次)
$array=array(1,"hello",1,"world","hello");
print_r(array_count_values( $array));
2、array_key_exist(搜索能不能找到键名,找到为true,否则为false)
$search_array=array('first' =>1,'second'=>4);
var_dump(array_key_exists('sunshengli', $search_array));
3、array_search(搜索数据,需要检查类型时在后面加true即可)
$array = array(0 =>'blue',1=>'red',2=>'green',3=>'green',4=>15 );
var_dump(array_search('15', $array,true));
4、count(计算数组有多少个数)
$array = array(0 =>'blue',1=>'red',2=>'green',3=>'green',4=>15 );
var_dump(count( $array));
5、in_array(检查是否存在某个值)注:区分大小写
$os=array("mac","nt","itmix","linux");
var_dump(in_array('mac', $os));
6、list(把数组中的值赋给某些变量)注:是从右往左赋值,而不是从左往右
$arr=array(60,80,100);
list( $sunshengli, $xiaohong, $xiaoming)=$arr;
echo $sunshengli;
7、asort(对数组进行排序并保持索引关系)
$students=array(
'sunshengli'=>60,
'lilei'=>80,
'hanmeimei'=>100,
'zhangsan'=>90
);
asort( $students);
print_r( $students);
8、array_filter(用回调函数过滤数组中的单元)
function odd($var)
{
return( $var % 2 == 1);
}
function even( $var)
{
return( $var %2 == 0);
}
$array1 = array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5);
$array2 = array(6,7,8,9,10,11,12);
echo "odd";
print_r(array_filter( $array1,"odd"));
echo "even";
print_r(array_filter( $array2,"even"));