首页 > 代码库 > Array数组

Array数组

array_diff_key() 例子

<?php
$array1
= array(‘blue‘  => 1, ‘red‘  => 2, ‘green‘  => 3, ‘purple‘ => 4);
$array2 = array(‘green‘ => 5, ‘blue‘ => 6, ‘yellow‘ => 7, ‘cyan‘   => 8);

var_dump(array_diff_key($array1, $array2));
?>

上例输出:array(2) { ["red"]=> int(2) ["purple"]=> int(4) }

 

 

array_diff_uassoc() 例子

<?php
function key_compare_func($a, $b)
{
    if (
$a === $b) {
        return
0;
    }
    return (
$a > $b)? 1:-1;
}

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_uassoc($array1, $array2, "key_compare_func");
print_r($result);
?>

上例输出:Array ( [b] => brown [c] => blue [0] => red )

 

 

 

 

Array数组