Some basic functions commonly used by PHP (I) 1. PHP declaration and use constant ?? Define (CONSTANT, 100); similar to this is to declare a CONSTANT, once declared elsewhere, it cannot be modified. Generally, our constants are composed of uppercase letters, and there is no $ symbol before the constant. 2. PHP compound operator $ a + $ B; equivalent to $ a + $ B $ a-$ B; it is equivalent to some basic functions commonly used in $ a-PHP (1)
1. PHP declaration and constant usage
?? Define ('constant', '100'); similar to this, a CONSTANT is declared and cannot be modified once declared elsewhere. Generally, our constants are composed of uppercase letters, and there is no $ symbol before the constant.
2. PHP compound operators
$ A + = $ B; equivalent to $ a = $ a + $ B
$ A-= $ B; equivalent to $ a = $ a-$ B
$ A. = $ B; equivalent to $ a = $ a. $ B. This is not used to connect strings (multiplication *)
3. differences between $ a ++ $
$ A = 4;
Echo ++ $;
$ A first adds the variable $ Aplus 1, and then assigns the result after adding 1 to the original variable. $ a is changed to 5, and the value of the entire expression is 5.
$ A = 4;
Echo $ a ++;
The value of $ a is returned to the screen, and $ a is added with 1. the value of this expression is 4, and the value of $ a is 5.
4. & as a reference
$ A = 5;
$ B = $;
The two lines of code first generate a copy of $ a and then save it to $ B. If the value of $ a changes subsequently and $ a = 7, the value of $ B does not change. Still 5.
$ A = 5;
$ B = & $;
If the $ a value is changed and $ a = 7, the value of $ B is changed to $ B = 7. The reference points both $ a and $ B to the same address in the memory.
5. a label that cannot be remembered
$ A & $ B ?? It must be true for both of them to be true [AND] at the same time.
$ A | $ B ?? True means true ?????? [OR]
6. ternary operators
($ Grade> = 55? 'Passed': 'failed ')
Condition ???? Val is true ?? Val is false
7. @ operator
$ A = @ (0/5); [email protected] generates a warning except 0. with this operator, this warning is blocked.
8. instanceof operator
This function allows you to check whether an object is an instance of a specific class.
Class sampleClass {}
$ My = new sampleClass ();
If ($ my instanceof sampleClass ){}
9. function: number_format ()
Number_format (number, decimals, decimalpoint, separator)
Parameter description:
Number is required. The number to be formatted. If no other parameter is set, the number is formatted as a comma (,) without a decimal point.
Optional. Specifies the number of decimal places. If this parameter is set, the period (.) is used as the decimal point to format the number.
Decimalpoint is optional. Specifies the string used as the decimal point.
Optional. A string that is required to be used as a thousands separator. Use only the first character of this parameter. For example, "xyz" only outputs "x ". Note: If this parameter is set, all other parameters are required.
Echo number_format ("1000000.777"); // after formatting, all decimal points are missing.
Echo number_format ("1000000", 2 );
Echo number_format ("1000000", 2 ,",",".");
?>
Output:
1,000,000
1,000,000.00
1.000.000, 00
10. functions settype () and gettype ()
$ Va = 54;
Echo gettype ($ va); // This is the type integer that outputs $ va
Settype ($ va, 'double'); // This is the double-precision type.
You can use is_double (); to test the function. The return value is true or false.