I am trying to check conditions inside foreach for a dynamic array.
My Array:
Array
(
[0] => Array
(
[type] => target_id
[operator] => Equals
[value] => 13
[operation] => OR
)
[1] => Array
(
[type] => target_id
[operator] => Equals
[value] => 14
[operation] => OR
)
[2] => Array
(
[type] => target_id
[operator] => Equals
[value] => 15
[operation] => OR
)
)
Say I have a variable:
$target_id = 14;
I want to check this way
$override = false;
foreach($array as $key => $value){
if($value["type"] == "target_id" && $value["operator"] == "Equals"){
if($target_id == $value["value"]){
$override = true;
}
}
}
If I generate a filter string, it would look like: 13 == 14 OR 14 == 14 OR 14 == 15
So my logic would be if(13 == 14 OR 14 == 14 OR 14 == 15)
I am not sure how to add the operation condition inside foreach. Can anyone point me to the right direction please?