1, write the application of the time will use this situation, such as a number rounded rounding. A lot of people would write this:
Copy Code code as follows:
Input A
If A-int (a) >= 0.5 then
A = a +1
End If
In fact, this judgment statement can be written using a very simple expression
Copy Code code as follows:
A = fix (A + SGN (a) *0.5)
Writing in PHP:
Copy Code code as follows:
$a = intval ($a + 0.5 * ($a >0 1:-1));
Analysis:
Suppose A is 4.4 then a+0.5 = 4.9 intval () after 4, assuming a is 4.6 a+0.5=5.1 then intval () then 5, thus rounding is achieved.
Positive +0.5, minus 0.5.
The same is true if rounding is reserved for 2 decimal places.
Copy Code code as follows:
$a = intval (A * + 0.5 * ($a >0 1:-1))/100.
2, if the value of a-b, if less than 0 then take 0, you can write the city
Copy Code code as follows:
$result = max (0, $a-$b);
3, import data, you can choose to use CSV format PHP for getcsv processing is very convenient.
4. Str_replace () Buzheng expressions are more efficient in substitution strings . In fact, according to the making web, Str_replace () is 61% more efficient than regular expressions like ereg_replace () and Preg_replace ().
5. if ($a ==true) if ($a)
6, using Isset to determine whether the variables and elements are high speed
7, try to use three mesh operation
8, appropriate to write if line statements. Use return statements to reduce branches appropriately within a function
9, use Memcache Mogodb and so on to reduce the program and the database burden
10, temporary data can use Sqllite record