I have a php record to check whether there is a more concise way of writing, or you can use other methods to implement {code ...} there is a php judge to see if there is a more concise writing method, or other methods can be implemented.
$cat_id = 0;if(empty($a)){ if(empty($b)){ if(empty($c)){ return 0; exit(); }else{ $cat_id = $c; } }else{ $cat_id = $b; }}else{ $cat_id = $a;}
Reply content:
There is a php judge to see if there is a more concise writing method, or other methods can be implemented.
$cat_id = 0;if(empty($a)){ if(empty($b)){ if(empty($c)){ return 0; exit(); }else{ $cat_id = $c; } }else{ $cat_id = $b; }}else{ $cat_id = $a;}
$ Cat_id = $? : $ B? : $ C? : 0; // PHP version requirements
Like writing this, no nesting
$cat_id = 0;if($a) { $cat_id = $a; return;}if($b) { $cat_id = $b; return;}if($c) { $cat_id = $c; return;}return;
$ Cat_id = $? $ A: ($ B? $ B: ($ c? $ C: 0 ));
$cat_id = 0;if (!empty($a)) { $cat_id = $a;} elseif (!empty($b)) { $cat_id = $b;} elseif (!empty($c)) { $cat_id = $c;} else { return 0;}
function test($a, $b, $c){ if (empty($a)) { if (empty($b)) { if (empty($c)) { return 0; } return $c; } return $b; } return $a;}$cat_id = test($a, $b, $c);
There should be no simpler writing method, but it can be optimized
$cat_id = 0;if (! empty($c)) $cat_id = $c;if (! empty($b)) $cat_id = $b;if (! empty($a)) $cat_id = $a;if (empty($cat_id)) exit;
function checkEmpty($a, $b = '', $c = ''){ if(empty($b) && empty($c)) exit(); return empty($a) ? checkEmpty($b,$c) : $a; }
This should be concise enough!
$cat_id = 0;while(1){ if(empty($a)){ $cat_id = $a; break; } if(empty($b)){ $cat_id = $b; break; } if(empty($c)){ $cat_id = $c; break; }}
Just do not write nesting.
High readability
Simplified and traditional