"red","b"=>"green")...">
美文网首页
PHP Array 函数二

PHP Array 函数二

作者: 谢凌 | 来源:发表于2019-06-19 10:25 被阅读0次

// 把多个数组合并为一个数组

        $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);

相关文章

网友评论

      本文标题:PHP Array 函数二

      本文链接:https://www.haomeiwen.com/subject/hcpuaqtx.html