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.