Variables in PHP

Source: Internet
Author: User
Tags http file upload
: This article mainly introduces the variables in PHP. if you are interested in the PHP Tutorial, you can refer to them. Overview

Variables in PHP are represented by a dollar sign followed by the variable name.

Variable names are case sensitive.

A valid variable name must start with a letter or underline followed by any number of letters, numbers, or underscores.

$ This is a special variable and cannot be assigned a value.

By default, values are always assigned. Use&
Only variables with names can reference values.

$ Foo = 25; $ bar = & $ foo; // valid value $ bar = & (24*7); // invalid; reference an expression without a name

Although you do not need to initialize variables in PHP, it is a good habit to initialize variables. Uninitialized variables have their own type default values-Boolean variables default values are FALSE, integer and floating point variables default values are zero, string variables (for example, used in echo) the default value is an empty string and an array variable. the default value is an empty array.

Predefined variables

Super global variables-Super global variables are built-in variables that are always available in all scopes $ GLOBALS-reference all variables available in the global scope $ _ SERVER-SERVER and execution environment information $ _ GET -http get variable $ _ POST-http post variable $ _ FILES-HTTP file Upload variable $ _ REQUEST-HTTP Request variable $ _ SESSION-Session variable $ _ ENV-environment variable $ _ COOKIE-HTTP Cookies $ php_errormsg-previous error message $ HTTP_RAW_POST_DATA-native POST data $ http_response_header-HTTP response header $ argc-number of parameters passed to the script $ argv-parameters passed to the script array

Many predefined variables in PHP are "super Global", which means they are available in all scopes of a script. You can access functions or methods without performing global $ variable.

Variable scope

The global variable is automatically invalid in the function.


  

Global variables in PHP must be declaredglobal


  

The second way to access variables globally is to use a special PHP custom$GLOBALSArray


  

Static variables

Another important feature of variable range is static variable ). Static variables only exist in local function domains, but their values are not lost when the program runs out of this scope.


  

Variable

Variable names can be dynamically set and used.

$Bar = "a";$Foo = "Bar";$World = "Foo";$Hello = "World";$a = "Hello";$a; //Returns Hello$$a; //Returns World$$$a; //Returns Foo$$$$a; //Returns Bar$$$$$a; //Returns a

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above describes the variables in PHP, including the relevant content, and hope to help those who are interested in the PHP Tutorial.

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.