$categories = [
['id' => 1],
['id' => 2],
['id' => 3],
['id' => 4],
['id' => 5]
];
$products = [
['id' => 1, 'cat_id' => 2],
['id' => 2, 'cat_id' => 3],
['id' => 3, 'cat_id' => 2]
];
$categories_ids = array_flip(
array_map(
function ($v) {return $v['cat_id'];},
$products
)
);
foreach ($categories as &$category) {
$category['isEmpty'] = !isset($categories_ids[$category['id']]);
}
print_r($categories);