php的一些数组用法

时间:2022-07-22 19:13:22
数组分割
array_chunk();
比较数组
1.
array_diff() array_diff_assoc()
2.
array_filter();
functionodd($var){
return($var%2==1);
}
functioneven($var){
return($var%2==0);
} $arrayarray1=array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5);
$arrayarray2=array(6,7,8,9,10,11,12);
echo"Odd:\n";
print_r(array_filter($array1,"odd"));
echo"Even:\n";
print_r(array_filter($array2,"even"));
?>
3.
array_map();
$a=array(1,2,3,4,5);
$b=array("uno","dos","tres","cuatro","cinco"); $c=array_map("show_Spanish",$a,$b); 4.str_split();