我有两个具有完全相同的键名但具有不同二进制值的数组。我想形成一个包含每个数组中二进制值的逻辑AND的数组。
例如:
$array1 = Array ([Ant] => 1 [Arm] => 1 [Ash] => 1 [AUB] => 0 [Bas] => 1 [Bay] );
$array2 = Array ([Ant] => 1 [Arm] => 0 [Ash] => 1 [AUB] => 1 [Bas] => 1 [Bay] );
$finalArray = ($array1 AND $array2);
//预期输出为:
$finalArray = Array ([Ant] => 1 [Arm] => 0 [Ash] => 1 [AUB] => 0 [Bas] => 1 [Bay] );
答案 0 :(得分:0)
您可以使用array_walk函数
array_walk($array1, function(&$value, $key) use ($array2) {
$value = $array2[$key] && $value;
});
$ array1将具有最终值