Variable constants in PHP Basics-php Tutorial

Source: Internet
Author: User
Variable constant variables in PHP Basics

In php, variable names start with a letter or underline after the dollar sign $, followed by any number of letters, numbers, or underscores.

Php> $ name = "Tom"; php> $ NAME = "Jack"; php> echo $ name; Tomphp> echo $ NAME; // the variable name is case sensitive to Jack.
1. variable assignment
  • Direct assignment

    When the value of a variable is assigned to another variable, changing the value of one variable does not affect another variable.

    Php> $ a = 10; php> $ B = $ a; php> $ a = 5; php> echo 'a value :'. $. "\ n ". 'B's value is '. $ B; the value of a is 5. The value of B is 10.
  • Reference assignment

    Changing new variables will affect the original variables, and changing the original variables will also affect the new variables. to use the reference value assignment, you must add the & symbol in front of the variable name.

    Php> $ a = 10; php> $ B = $ a; php> $ c = & $ a; php> $ a = 5; php> echo "the value of a is $ a \ n ". "The value of B is $ B \ n ". "The value of c is $ c"; the value of a is 5 and the value of B is 10. The value of c is 5.
2. variable operations
  • Declare?

    Bool isset (mixed $ var) returns true if $ var exists, and false if not.

      php > var_dump(isset($sex));  bool(false)  php > $sex = "man";  php > var_dump(isset($sex));  bool(true)
  • Empty or not

    Bool empty (mixed $ var) if $ var is not NULL or non-zero, false is returned; "", 0, "0", NULL, FALSE, array (), and objects without any properties will be considered null. If var is null, TRUE is returned.

      bool(true)  php > $name = "Tom";  php > var_dump(empty($name));  bool(false)
  • Release variable

    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 result: 3
  • $ GLOBALS array

      
       Output result: 3
4. static variables

Static $ var

Static variables only exist in the local function domain, but their values are not lost when the program runs out of this scope.

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

-

Constant

A constant is an identifier of a simple value. it is case sensitive and the identifier is always uppercase.

Define constants:Define ('identifier', 'corresponding value ')

php > define("NAME",'tom');php > echo NAME;tom

System constant

From php Manual

I am a beginner in php. I wrote these summaries during my study and shared them with you. if there are any inappropriate points, you are welcome to correct them. I will also accept your suggestions modestly, we hope to make progress together with you.

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.