Due to the pressure from the need side, the need to add a variety of if judgment in the program caused the program messy, do not know whether there is a scientific way to solve the problem.
Reply content:
Just answer the code skills, do not answer the schema, I think that there is no standard answer, of course, the small skill also depends on the specific use of the scene.
Go Ternary
if (A) $var = xxxelse $var = ooo↓$var = A ? xxx : ooo
Learn more about OOP, Factory mode \ policy mode \ Adorner mode. You can use polymorphism instead of conditional judgment, and refer to the implementation of design patterns such as simple Factory mode or strategy mode.
Switch can not write as many judgments as if-else, but it is still not able to meet the requirements of closed, extended open. Is it estimated that nesting if causes clutter? Exception Problem Solving reference refactoring: improving the design of existing code chapter 9th-Simplifying conditional expressions
Replace Nested Conditional with guard claused (replace nested conditional expressions with Guardian statements) You can look at the notation of large frames!! Recommended zendframework with arrays and closures I think a good, high-reading program or do not omit curly braces, do not use too much three mesh operations, but also less with && this logical operator to replace the conditional judgment. Really want to make if concise, I think should be less with the if after the else, give a lot of return value, say the next judge in another if block, in addition, we should learn to design patterns, reduce if statement less than set. Judge1
if (!expression) {
Code
[Return/break]}
Judge2
if (!expression) {
Code
[Return/break]}
... switch, haha