从一个数组中获取键及其值的最佳方法,而另一个数组不存在这些键及其值,仅通过其键进行比较


Best way to get keys and its values from an array which are not existent in another array compared only by its keys

hi我想在与另一个数组比较时过滤掉一些键和值。"内容"对应显示在末尾。。。非常感谢您的帮助!

<?php
$test = array(
            ['slideid'] => 597,
            ['token'] =>'4e23fdd176372984870a9c65db7133b5',
            ['content'] =>'<p>sdg</p>',
        )
$test2 = array(
            ['slideid'] => "",
            ['token'] =>""
            )
foreach ($test not in $test2){
    print $test2
} //not working of course   
?> 

这是有效的:

$test = array(
    'slideid' => 597,
    'token' =>'4e23fdd176372984870a9c65db7133b5',
    'content' =>'<p>sdg</p>'
);
$test2 = array(
    'slideid' => "",
    'token' =>""
);
foreach ($test as $key => $value){
    if (!array_key_exists($key, $test2)) {
        echo $value;
    }
}

$arr包含在test但不在test2 中的元素

$arr = array_diff(array_keys($test), array_keys($test2));
print_r($arr);