I ran into a coding situation where i'd prefer to keep a certain condition as compact as possible:
// $data and $control are arrays
if($data==$control || ($someBool && $data==$control))
return $c;
Of course this condition makes no sense that way. My goal is to remove a key from $control
in the last part of my condition, before comparing it against $data
.
Of course it could be done like this:
function chopByKey(array $arr, $key){
if(!isset($arr[$key]))
return $arr;
unset($arr[$key]);
return $arr;
}
And rewrite the condition:
if($data==$control || ($someBool && $data==chopByKey($control, 'someKey') ))
return $c;
Please note
I am looking for a solution that i can use within my condition, not any solution that requires any additional step ahead of the condition or the definition of a custom function, be it anonymous or not.
My question is
Is there any more elegant way to do this, without defining a new custom function?
If yes, how?