PHPMYSQL basic tutorial 1. three methods of annotation
① # Comment The shell style here
② // Note the c ++ style here
③/* Comments */c-style multi-line comments should not be placed in one line (single-line comments should be used //) to prevent unnecessary errors
2. variables
① The variable starts with $
② The variable name is composed of strings, underscores, and numbers.
③ The variable name must start with a string or underline and cannot start with a number.
④ Variable names are case sensitive. $ name and $ Name are not variables.
⑤ The variable can be assigned a value using =.
3. variables in PHP 8
Four scalar types: Boolean (true and false), integer, floating point, string
Two non-standard values: Array and object
Resources
Null does not have any special type of value
4. echo () and print (), printf (), sprintf ()
① Void echo (string arg1 [, string arg2,... string argn]);
② Int print (arg );
③ Printf () can output content mixed with static text and dynamic information transmitted through variables.
Boolean printf (string format [, mixed args]);
For example, printf ("bar inventory: % d bottles of tonic water", 100 );
Output bar inventory: 100 bottles of water
Here % d is a placeholder to indicate that the output is an integer.
Placeholders:
Parameter description
% B Indicates that the parameter is regarded as an integer and displayed as a binary number.
% C considers the parameter as an integer and displays it as an ASCII character.
% D: the parameter is regarded as an integer and displayed as a signed decimal number.
% F considers the parameter as a floating point number and displays it as a floating point number.
% O considers the parameter as an integer and displays it as a signed octal number.
% S: the parameter is considered a string and displayed as a string.
% U indicates that the parameter is an integer and is displayed as an unsigned decimal number.
% X is an integer that is considered as a lowercase hexadecimal number.
% X indicates that the parameter is regarded as an integer and is displayed as a hexadecimal number in uppercase.
If you want to input two parameters
Printf ("% d bottles of tonic water cost $ % f", 100,43, 20 );
When using decimals, you can use a precision indicator to adjust the precision.
Printf ("$ %. 2f", 43.2); // $43.20
④ Sprintf ()
Similar to printf (), but it assigns the output to a string instead of the output on the browser.
String sprintf (string arg [, mixed args]);
Example: $ cost = sprintf ("$ %. 2f", 43.2); // $ cost = 43.20;
5. type conversion
(Array) to an array
(Bool)/(boolean) boolean value
(Int)/(integer) integer
(Object) object
(Real)/(float)/(double) floating point type
(String) string
Any data type can be converted to an object. The result is that the variable becomes an attribute of the object, which is named scalar.
$ Model = 'test ';
$ Obj = (object) $ model;
Echo $ obj-> scalar; // test
An integer that starts with an integer and is converted to an integer. Otherwise, the conversion result is 0.
If a string containing./e/E is used in mathematical computation, the string is calculated as a floating point.
$ Val1 = "1.2e3"; // 1,200
$ Val2 = 2;
Echo $ val1 * $ val2/2400
6. gettype (), settype ()
String gettype (mixed var) // obtain the type
Obtain the type of the variable specified by var. the return type is 8:
Array, boolean, double, integer, object, resource, string, unknow type
Boolean settype (mixed var, string type );
Set the type of the variable specified by var to the type specified by type, with 7 types:
Array, boolean, integer, float, object, null, string
7. determine the variable type
Boolean is_name (mixed var );
Is_name includes the following functions:
Is_array (), is_bool (), is_float (), is_integer (), is_string (), is_object (), is_resource (), is_null ()
Is_scalar (), is_numeric ()