I would like to ask you a lot about how to optimize or circumvent such a phenomenon by referring to the code programming specifications?
I would like to ask you a lot about the logic judgment, but it seems too complicated.Code programming specifications
For reference, howOptimizationOrAvoidanceWhat about this phenomenon?
Reply content:
I would like to ask you a lot about the logic judgment, but it seems too complicated.Code programming specifications
For reference, howOptimizationOrAvoidanceWhat about this phenomenon?
Experience problems. Separately, if (! Is_array). This may come from the following requirements:
We have a number and want to compare it with another one. What is the other? You can enter the number at will, but it must be greater than 5, less than 7, about 8, less than or equal to 10, do it for you.
Then you did it. No error.
Because developers who do not understand development can describe their needs in a realistic manner, I think developers should have their own understandings. For example, I will abstract them:
Compare the number A with the expected expression B and obtain the result. Expression B contains the operator and the operand. That is, expression B should conform to the Regular Expression/^([^\d]+)(\d+)$/
Where $1 is the operator and $2 is the operand. The operator must be <, <=,>,> =.
In this way, the code will be similar
// $ A operand A, $ B, expression B, $ c, operator, $ n2 second operand if (! Preg_match ('/^ \ d + $/', $ a) {die ('a invalid ');} if (! Preg_match ('/^ ([^ \ d] +) (\ d +) $/', $ B, $ _ match) {die ("format error ");} $ c = $ _ match [1] [0]; $ n2 = $ _ match [1] [1]; $ useableC = array ('<', '<= ', '>', '> ='); if (! In_array ($ c, $ useableC) {die ('invalid operator ');} eval ("\ $ t = $ a $ c $ n2 "); if ($ t) echo 'y'; echo 'n ';
Obviously, you can easily extend it to more operators, and then add = ,! = Very convenient.
The above is a pseudo code. We do not recommend using regular expressions as the final standard for digit validity verification.
The writing skills are poor. I don't know what you want to express. I hope it can help.