// 把多个数组合并为一个数组
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
$res= array_merge($a1,$a2);
show_json($res);
// 返回包含数组中所有键名的一个新数组
$a=array("Volvo"=>"XC90","BMW"=>"X5");
$res= array_keys($a);
show_json($res);
// 检查键名 是否存在于数组中
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Volvo",$a))
{
$res= "Key exists!";
}
else
{
$res= "Key does not exist!";
}
show_json($res);
// 比较数组,并返回交集:
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$a11=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a21=array("a"=>"red","b"=>"green","c"=>"blue");
$a12=array("a"=>"red","b"=>"green","c"=>"blue");
$a22=array("a"=>"red","c"=>"blue","d"=>"pink");
$res[]=array_intersect($a1,$a2);
$res[]=array_intersect_assoc($a11,$a21);
$res[]=array_intersect_key($a12,$a22);
show_json($res);
// 反转数组中的键名和对应关联的键值
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$res=array_flip($a1);
show_json($res);
网友评论