PHP Lesson 3: basic data types of PHP. Lesson 3 PHP basic data type learning outline: 1. php 7 variable types 2. differentiation of isset and empty functions 3. type Test 4. type conversion 5. forced type conversion note: PHP lesson 3 basic PHP Data types
Learning outline:
1. php seven variable types
2. differences between isset and empty functions
3. type test
4. automatic type conversion
5. forced type conversion
Note:
1. the call method in the object is called through the variable-> method name. $ user1 = new per (); $ user1-> say ();
2. change the page encoding:
Header ("content-type: text/html; charset = gbk ");
3. the header information cannot be output.
1. php eight variable types
Integer
Floating point type
Character type
Boolean
// The above four types are scalar types
Array
Object
// The above two types are composite types
Resources
Null type
// The above two types are special
Integer
$ A = 10;
Floating point type
$ A = 10.3;
Character type
$ A = "Hello World ";
Use. to link strings
Boolean
$ A = true;
Boolean types are generally obtained by comparison operations,> <>==! ===! =
When echo print_r is used to output a Boolean type, true is changed to 1, and false is null.
$ A = true;
Var_dump ($ );
Array
// Definition: when multiple values are assigned to a variable
";print_r ($arr);echo "
";?>
Array Value:
Add an array:
Object Type
// An object consists of features and functions, attributes, and methods.
Say ();?>
Resources
Null type
$ A = null;
Database-based linked resources and operation tables:
2. differences between isset and empty functions
Whether the isset variable exists and does not exist:
1) no definition
2) null
Whether or not the empty variable is empty:
1) 0
2 )""
3) "0"
4) false
5) array ()
6) null
7) No definition
3. type test
Var_dump ();
1. integer is_int ();
2. float is_float ();
Database connection: $ Conn = mysql_connect ("localhost", "root", "1234 ");
Var_dump (is_resource ($ conn ));
?>
4. automatic type conversion
1. integer-> string
2. string-> integer
$ Num = "1243alj ";
// The string is automatically converted to an integer.
Echo $ num + 1;
3. other types-> boolean type
1) 0
2 )""
3) "0"
4) false
5) array ()
6) null
7) No definition
// The Boolean type above is false.
5. forced type conversion
(Int) $ num integer
(Float) $ num floating point type
(String) $ num String
(Bool) $ num Boolean
Use to delete variables:
$ Num = "user ";
Unset ($ num );
Var_dump (isset ($ num ));
Single double quotation marks of a string:
1. if no variable exists in the string, use single quotation marks.
2. if there is a variable, use double quotation marks (single quotation marks can also be used, but must be linked)
Constant definition:
// Same as the variable, but cannot be modified once defined
Define ("HOST", "localhost ");
Define ("USER", "root ");
Define ("PASS", "123 ");
Define ("DBNAME", "test ");
// For example, the database configuration file must use constants and cannot be modified later.
Constant output:
Echo HOST;
Constants cannot be placed in double quotation marks.
Echo "my host is". HOST;
Operator
The basic data type learning outline of structured PHP: 1. php 7 variable types 2. differentiation of isset and empty functions 3. type Test 4. type conversion 5. note :...