Hi @requinix , Thank you for your explanation and for taking the time to solve this problem. The whole recursive approach I really do not follow that method because I find it really confusing and hard, however, I am able to break it through my existing solution. Below I have simply break the loop if the `vehicle_info` `key` does not match
$commonArray = [];
$total = count($products) - 1;
$vehicles = $products[0];
array_shift($products);
foreach ($vehicles as $key => $vehicle) {
foreach ($vehicle['vehicle_info'] as $ktype => $fitments) {
$countKey = 0;
// check all the products
foreach ($products as $index => $product) {
if (!isset($product[$key]['vehicle_info'])) {
// key not found in this product, move on to next key
break 2;
}
foreach ($product[$key]['vehicle_info'] as $kt => $fits) {
if ($ktype == $kt) {
$countKey++;
if ($countKey == $total) {
$commonArray[$key] = $product[$key];
}
}
}
}
}
}
print_r($commonArray);
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.