I have a multidimensional array:
$array =
Array (
[0] => Array ( [id] => 2 [zoneId] => 2 [buildingId] => 2 [typeId] => 2 )
[1] => Array ( [id] => 4 [zoneId] => 2 [buildingId] => 2 [typeId] => 1 )
[2] => Array ( [id] => 6 [zoneId] => 6 [buildingId] => 17 [typeId] => 2 ) )
And I would like to search if the combination of, for example, [buildingId] => 2, [typeId] => 2 exists is array 0, 1 or 2.
I tried the following:
$keyType = array_search(2, array_column($array, 'typeId'));
$keyBuilding = array_search(2, array_column($array, 'buildingId'));
if(is_numeric($keyType)&&is_numeric($keyBuilding)){
echo 'Combination does exists'
}
This works, but gives also a false positive if I would search for [buildingId] => 17, [typeId] => 1. How can I solve this?
edit
I would also like to know if a combination is not in the array, how can I arrange that?
if($result == false){
echo 'does not exists';
}