Variable Constants for PHP basic articles

Source: Internet
Author: User

Variable

The variable names in PHP are followed by the dollar sign $ after the variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

php > $name = "Tom";p hp > $NAME = "Jack";p hp > Echo $name; tomphp > Echo $NAME; Variable names are case-sensitive jack

1. Assigning values to variables

    • Direct Assignment

      When the value of one variable is assigned to another variable, changing the value of one of the variables will not affect the other variable.

        php > $a = ten;  php > $b = $a;  php > $a = 5;  The value of PHP > Echo ' A is: '. $a. ' \ n "." The value of B is '. $b;  The value of A is: 5  B has a value of 10
    • Reference assignment

      Altering the new variable will affect the original variable, and changing the original variable will also affect the new variable, using the reference assignment to add the & symbol in front of the variable name.

        php > $a = ten;  php > $b = $a;  php > $c = & $a;  php > $a = 5;  The value of PHP > echo "A is $a\n". " The value of B is $b\n "." The value of C is $c ";  A has a value of 5 B with a value of  ten  C of 5

2. Operation of variables

    • Whether to declare

      BOOL Isset (mixed $var) returns True if $var exists, and false is not present.

        php > Var_dump (isset ($sex));  BOOL (FALSE)  php > $sex = "man";  php > Var_dump (isset ($sex));  BOOL (TRUE)
    • is empty

      BOOL Empty (mixed $var) returns FALSE if $var is non-null or nonzero, "", 0, "0", NULL, FALSE, Array (), and objects that do not have any properties will be considered empty, and returns TRUE if Var is empty.

        BOOL (TRUE)  php > $name = "Tom";  php > Var_dump (Empty ($name));  BOOL (FALSE)
    • Releasing variables

      void unset (mixed $var [, mixed $var [, $ ...]] destroys the specified variable $var.

        php > $name = "Tom";  php > Var_dump (isset ($name));  BOOL (TRUE)  php > unset ($name);  php > Var_dump (isset ($name));  BOOL (FALSE)

3. Global variables

    • Global keyword

        
         
            Output results: 3
    • $GLOBALS Array

        
         
            Output results: 3

4. Static variables

Static $var

A static variable exists only in the local function domain, but its value is not lost when the program executes away from the scope.

function test () {    static $count = 0;    $count + +;    echo $count;    if ($count <) {        test ();    }    $count--;} Test (); output result: 12345678910

-

Constant

Constants are identifiers of simple values, are case-sensitive, and identifiers are always uppercase.

Define constants: define (' identifiers ', ' corresponding values ')

php > Define ("NAME", ' Tom ');p hp > Echo name;tom

System constants

Excerpt from PHP manual

I am a PHP beginner, in the study of the time to write these summaries and everyone to share, there are inappropriate places to welcome everyone to correct, I will humbly accept the suggestions of everyone, and we hope and common progress.

  • 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.