PHP learning notes [8] -- Introduction to php Data types and php operators
1. first, PHP is a weak language, which is case sensitive.
2. PHP defines a variable starting with $ a = 890 integer.
3. the variable type is not constant $ a = 1.1 Decimal type
The data type of the variable is determined by the running time.
4. the variable name must start with a letter or underscore and cannot start with a number or special character.
5. php data type:
Basic data type
Integer
Float (no dual precision or single precision)
Boolean
String
Composite data type
Array)
Object)
Special Data types
NULL
Resource Type $ conn = mysql_connect ("localhost", "root", "root ");
Integer
Definition: $ a = 10
1 ,? What are the following results?
$;
Echo $;
Appearance: Notice: Undefined variable:
If no value is assigned, no memory is allocated to variable a, which is equivalent to no definition.
2. use the following actual number of bytes occupied by the int type and the maximum number of bytes occupied by the int type.
Echo PHP_INT_SIZE
Echo PHP_INT_MAX
Boolean
Definition: $ a = true; $ B = false; (true, false is case insensitive)
1. the integer value 0 and decimal number 0.0 are both false.
2. Both the null string "" and the string "0" are false.
3. the array that does not contain elements is false.
4. the object that does not contain any member variables is false.
5. the special variable NULL is false.
String
Definition: $ a = 'hello ';
1. how many bytes does a occupy?
Five
2. one character in the string occupies one byte.
3. the size of the string can be infinitely large.
4. we can use single quotation marks and double quotation marks when defining strings.
Case 1
$ I = 90
Echo "hello: $ I"; parse $ I
Echo 'hello: $ I '; original output
Case 2
Echo "abcd \"; double quotation marks resolved
Echo 'abcd \ "'; not parsed
Echo 'abcd \ '; resolve single quotes with single quotes
Echo "abcd \ '"; not parsed
Case 3
Echo "\ n"; parse line feed "" will parse special characters
Operator
- $ A = 90;
- $ A ++; // auto-increment operator
- Echo $ ."
"; // 91
- Echo $ a ++; // Output $ a first and then add // 91
- Echo ++ $ a; // add and then output $ a 93
- $ B = 90;
- $ B --; // auto-subtraction operator
- Echo $ B ."
";
- // Subtract left
- $ B-= 2;
- $ B + = 2;
- $ B/= 2;
- $ B % = 2;
- // Different comparison operators in php
- If ($ a ===$ B ){
- Echo "this is equality, indicating that a and B are equal, and their types are the same. ";
- }
- If ($! ==$ B ){
- Echo "this is not all, indicating that a and B are not equal, or their types are different. ";
- }
- If ($ a <> $ B ){
- Echo "a is not equal to B ";
- }
- // Logical operators
- If ($ a and $ B) {// $ a & $ B
- Echo "both logic and a and B are true ";
- }
- If ($ a or $ B) {// $ a | $ B
- Echo "logical OR a or B is true ";
- }
- If ($ a xor $ B ){
- Echo "the logic is different or only one of a and B is true, and there is only one ";
- }
- // Note that the or and priority ratio = location
- $ A = false or true;
- Var_dump ($ a); // the result of this statement is false. because the priority of or is lower than =, false is assigned to $.
- // The interview questions and & all indicate logic and where are their differences?
- // Mainly reflected in priority
- // And has a priority less than or equal to priority &&
- // Ternary operators
- $ A = 90;
- $ B = 80;
- $ C = $ a> $ B? 900;
- Echo"
". $ C;
- // String
- $ A = "hello ";
- $ B = "world ";
- $ C = $ a. $ B;
- Echo"
". $ C ."
";
- // The type operator is used to determine the data type of a php variable.
- Class Dog {}
- Class Cat {}
- $ Cat1 = new Cat;
- Var_dump ($ cat1 instanceof Dog); // determines whether an object belongs to a class.
- ?>