我有两个多维数组,
$textEvaluasi = [
[0]=>[
[0] => "BTC Hotel",
[1] => "Hotel Jaya"
]
,
[3]=>[
[0] => "BTC Hotel"
]
,
[4]=>[
[0] => "Lokasi BTC Hotel"
]
,
[5]=>[
[0] => "Lokasi BTC Hotel"
]
];
并且:
$hasil = [
[0]=>[
[0] => "BTC Hotel",
[1] => "Hotel Jaya"
]
,
[3]=>[
[0] => "BTC Hotel"
]
,
[4]=>[
[0] => "BTC Hotel"
]
,
[5]=>[
[0] => "BTC Hotel"
]
];
我需要比较$textEvaluasi
和$hasil
,如果键和值匹配,那么我将打印键和值。
我已经尝试但是它无法正常工作。这就是我现在正在做的事情:
foreach ($textEvaluasi as $key => $value) {
foreach ($value as $key2 => $value2) {
foreach ($hasil as $key3 => $value3) {
foreach ($value3 as $key4 => $value4) {
if (strtolower($textEvaluasi[$key][$key2]) === strtolower($hasil[$key3][$key4])){
echo $key . $value2;
}
}
}
echo "<br>";
}
}
我的代码输出是:
[0] -> BTC Hotel
[3] -> BTC Hotel
[4] -> BTC Hotel
[5] -> BTC Hotel
预期产出:
[0] -> BTC Hotel, Hotel Jaya
[3] -> BTC Hotel
非常感谢任何帮助,谢谢。
答案 0 :(得分:2)
您可以使用array_filter
,如下所示:
$result = array_filter($textEvaluasi, function ($arr, $key) use ($hasil) {
return $hasil[$key] === $arr;
}, ARRAY_FILTER_USE_BOTH);