PHP learning notes [8] -- Introduction to php Data types and php operators

Source: Internet
Author: User
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

 
 
  1. $ A = 90;
  2. $ A ++; // auto-increment operator
  3. Echo $ ."
    "; // 91
  4. Echo $ a ++; // Output $ a first and then add // 91
  5. Echo ++ $ a; // add and then output $ a 93
  6. $ B = 90;
  7. $ B --; // auto-subtraction operator
  8. Echo $ B ."
    ";
  9. // Subtract left
  10. $ B-= 2;
  11. $ B + = 2;
  12. $ B/= 2;
  13. $ B % = 2;
  14. // Different comparison operators in php
  15. If ($ a ===$ B ){
  16. Echo "this is equality, indicating that a and B are equal, and their types are the same. ";
  17. }
  18. If ($! ==$ B ){
  19. Echo "this is not all, indicating that a and B are not equal, or their types are different. ";
  20. }
  21. If ($ a <> $ B ){
  22. Echo "a is not equal to B ";
  23. }
  24. // Logical operators
  25. If ($ a and $ B) {// $ a & $ B
  26. Echo "both logic and a and B are true ";
  27. }
  28. If ($ a or $ B) {// $ a | $ B
  29. Echo "logical OR a or B is true ";
  30. }
  31. If ($ a xor $ B ){
  32. Echo "the logic is different or only one of a and B is true, and there is only one ";
  33. }
  34. // Note that the or and priority ratio = location
  35. $ A = false or true;
  36. Var_dump ($ a); // the result of this statement is false. because the priority of or is lower than =, false is assigned to $.
  37. // The interview questions and & all indicate logic and where are their differences?
  38. // Mainly reflected in priority
  39. // And has a priority less than or equal to priority &&
  40. // Ternary operators
  41. $ A = 90;
  42. $ B = 80;
  43. $ C = $ a> $ B? 900;
  44. Echo"
    ". $ C;
  45. // String
  46. $ A = "hello ";
  47. $ B = "world ";
  48. $ C = $ a. $ B;
  49. Echo"
    ". $ C ."
    ";
  50. // The type operator is used to determine the data type of a php variable.
  51. Class Dog {}
  52. Class Cat {}
  53. $ Cat1 = new Cat;
  54. Var_dump ($ cat1 instanceof Dog); // determines whether an object belongs to a class.
  55. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.