Php learning notes 1--PHP data type, data storage, learning notes data type

Source: Internet
Author: User
Tags float number form post php operator

Php learning notes 1--PHP data type, data storage, learning notes data type
PHP Data Type scalar data type:

Type Chinese name Description
Boolean Boolean TRUE or FALSE (true false)
String String type Single quotes "Do not parse variables, output variable names as is (theoretically faster than double quotes)
- - Double quotation marks (") are used to parse variables and output variable values.
- - Delimiter <\ FFF // equivalent to multiple double quotation marks ("")
- - FFF; // occupies a single row with no extra spaces
Integer INTEGER (int) The signed integer php does not contain an unsigned integer.
Float Floating Point Type Float number (with decimal point or E)

Escape Character, \ '\ n \ r \ t \ "\ %...

Composite data type:
Type Chinese name Description
Array Array A set of data (which can be any data, including arrays), element, index (subscript/key name) --- Element
- - $ Arr = array (, 3, 'bb'); // No key name is specified, and the index starts from 0.
- - $ Arr [key] = value; // same as above
- - $ Arr = arry ('key' = 'value', 'key' = 'value '... Tec) // specifies the key name
Object Object Class instantiation
- - Class Gun {}; $ obj = new Gun (); // defines a class and instantiates an object
Special Data Types:
Type Chinese name Description
Resource Resources Saves a referenced variable of an external resource, such as opening a file/graphic canvas.
Null Null Value Variable with no initial value assigned
- - Null variable
- - Variable processed by the built-in function unset ()
Data Type Conversion


  • Automatic conversion: When the scalar data type is involved in the type, the PHP parser will automatically convert according to the actual situation
  • Forced conversion: Use the PHP operator or built-in function to forcibly change the variable quantity type
    • Function:
      • Intval ($ var); // forcibly convert to an integer (integer)
      • Floatval ($ var); // forcibly converted to float
      • Stringval ($ var); // force convert to struct type
      • Settype ($ var, type); // type indicates the target data type.
      • Unset ($ var); // convert to null to destroy the variable
    • OPERATOR:
      • (Int/integer) $ var;
      • (Float) $ var;
      • (String) $ var;
      • (Bool/boolean) $ var;
      • (Array) $ var;
      • (Object) $ var;
  • Type Detection:
    • Is_bool ($ var );
    • Is_int ($ var );
    • Is_float ($ var );
    • Is_string ($ var );
    • Is_array ($ var );
    • Is_object ($ var );
    • Is_null ($ var );
    • Is_numeric ($ var); // determines whether the variable is a number (numeric numbers are also OK)

Var_dump ($ var); // print the detailed attributes of a variable.

PHP constants and variable constants, used to store unchanged data in a program

The define () function is used for declaration. The declared value cannot be changed. The constant name must start with an underscore or a letter. The $ character is not required. It is case-sensitive and generally uppercase.

Bool define (sting $ name, mixed $ value [, bool $ case]); // bool $ case, true or false, true is case insensitive, and vice versa, default Value: false eg: define (FILENAME, 'huwhois '); // defines the constant FILENAME. The value is huwhois, Which is case sensitive.
Use the defined () function to determine whether it is defined as a constant.
Defined (FILENAME); // determines whether the FILENAME is defined as a constant. The return value is true or false.
Common predefined constants in php (which can be used directly ):
_ FILE __, current FILE path _ LINE __, current PHP program number of lines PHP_VERSION, current PHP version PHP_ OS, current PHP operating system Boolean value: TRUE FALSEE_ERROR, php error level code E_WARNING, warning level code E_ERROR, Syntax Parsing potential problem level code E_NOTICE, this constant is unusual, but not necessarily the error level code
Variable used to store data that can be changed in the program's median.

$ Name [= value];

Note:
* Add a $ sign before the variable name.
* The variable name must start with a letter or underline and can be followed by letters, underscores, and numbers.
* Variable names are case sensitive.
* Variable names cannot have the same name as built-in variables, functions, and constants.

Variable Assignment Method:
  • Direct value assignment, with the value = // $ a = 5;
  • Assign a value to another variable (pass a copy )// B = A ==>>> $ B = 5
  • Reference Value assignment to share the memory space of one variable with that of another variable
    • A = 5, C = & A, ==>> C = 5; if The c value has changed, A also changes with the value.
    • When you use the unset () function to destroy one of them, the other will not be affected.
The scope of variables, that is, the scope of variables, is mainly php preset variables determined based on their declaration methods and locations.

It is also called a super global variable. It is defined by the system and can be used directly to store related information in arrays.

  • $GLOBALSAll variables available in the global scope. PHP stores all global variables in the array named $ GLOBALS [index]. The variable name is the key of the array.
  • $ _ SERVER stores super global variables for header, path, and script Location Information
  • $ _ REQUEST Storage$_POSTAnd$_GETAll variables
  • $ _ POST stores the value submitted by form post
  • $ _ GET stores the value submitted by get
  • $ _ FILES stores uploaded file information
  • $ _ ENV storage environment variable
  • $ _ COOKIE storage cookie
  • $ _ SESSION storage session
Copyright Disclaimer: This article is an original article by the blogger. You are welcome to repost it.

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.