1. echo () function return value: voidecho indicates that the string is output to the browser 2. note #*...... * 3. print (), printf (), print_r () print () function return value: int; to output the string echoprint (& quot; print & quot;) to the browser. output result: print1echo print 1. echo () function return value: void
Echo: returns a string to the browser.
2. Note //#/*......*/
3. print (), printf (), print_r ()
Print () function return value: int;
Returns a string to the browser.
Echo print ("print ");
Output result: print1
Echo prints the print return value.
The printf () function returns the length of the string;
(Chinese accounts for two)
Printf ("I bought % d sets of CDS today", 10 );
Output: I bought 10 sets of CDS today.
The sprintf () function string is retained in the memory;
Echo is required to output
Echo sprintf ("123 ");
The print_r () function prints the variable itself;
Print the array if it is an array.
$ A = array ('A', 'B', 'C', 'D ');
Print_r ($ );
3. identifier and variable
The identifier is the variable name.
An identifier can be of any length and can contain any letter, number, or underline.
The identifier cannot start with a number.
In PHP, the identifier is case sensitive.
A variable name can be the same as a function name.
Create variable: $ sum = 0; $ name = "names ";
Variable types are determined by assigning values.
Variable type:
PHP supports the following basic data types:
Integer, Float (Double), String, Boolean, Array, Object
Type conversion:
$ Num = 1;
$ Total = (float) $ num;
* Check the variable type.
Gettype () checks the variable type;
$ A = 3.14;
Echo gettype ($ );
Output result: Double
Settype () sets the variable type;
$ Sum = 100;
Settype ($ sum, "string ");
Echo gettype ($ sum );
Output result: string
* Check whether the variable exists
Isset (); // determines whether a variable exists
$ A = 1;
Echo isset ($ a); // return a Boolean value.
If $ a exists, return: 1
Unset (); // destroy the variable
Unset ($ );
Destroy variable $;
Empty ();
Echo empty ($ );
Check whether the value of a variable is null. if it is null, 1 is returned.
Type judgment function
Is_array (), is_double (), is_float (), is_real (), is_long (),
Is_integer (), is_string (), is_object (), is_resource (),
Is_null (), is_numeric ()
$ Num = 100;
Is_interger ($ num );
Variable data type conversion function (temporary conversion ):
Intval (), floatval (), strval ()
$ Num = 22.22;
$ A = intval ($ num );
Intval ($ num) is converted to an integer.
$ Num type not changed
Super global variable:
$ GLOBALS [all global variable arrays]
$ _ SERVER [SERVER environment variable array]
$ _ GET [variables passed to the script through the GET method]
$ _ POST [variables passed to the script through the POST method]
$ _ COOKIE [cookie variable array]
$ _ FILES [array related to file Upload]
$ _ REQUEST [array of variables input by all users]
$ _ SESSION [SESSION variable array]
Constant: the amount that cannot be changed after being defined
Constant no $ operator
Constants can only store Boolean, integer, floating point, or string data.
Defin ("TOTAL", 100 );
TOTAL is always 100
4. access form variables
$ _ POST ["username"];
$ _ GET ["username"];