$regionFilter = isset($additionalDate['region']) && in_array($additionalDate['region'], $this->request["insuranceCompanyRegion"]);
$cityFilter = isset($additionalDate['city']) && in_array($additionalDate['city'], $this->request["insuranceCompanyCity"]);
if($isRegionFilter && $isCityFilter){
$filterCondition = $regionFilter && $cityFilter;
}elseif($isCityFilter){
$filterCondition = $cityFilter;
}elseif($isRegionFilter){
$filterCondition = $regionFilter;
}
if ($filterCondition) {
$this->companyIds[$q->id] = $q->name;
}
I need to make this condition simpler to edit in the future, how can I make it?
CodePudding user response:
if ($regionFilter || $cityFilter) {
$this->companyIds[$q->id] = $q->name;
}
CodePudding user response:
You can use shorthand If / Else check this 1 so for example
if($isRegionFilter && $isCityFilter){
$filterCondition = $regionFilter && $cityFilter;
becomes
$filterCondition=($isRegionFilter && $isCityFilter) ? $regionFilter && $cityFilter;
CodePudding user response:
$filterCondition=($isRegionFilter && $isCityFilter) ? $regionFilter && $cityFilter : (($isRegionFilter) ? $regionFilter : $cityFilter);