What are the rules for naming variables in PHP, and I'm sure you all know that simple but fine-grained estimates don't know, let's take a look at the declaration of PHP variables and the introduction of variable naming rules.
Which of the following three formulations is correct?
In a PHP program, what are the naming conventions for variables, and which of the following three formulations is correct?
The 1th type:
<?php $myname = ' AA ';? >
The 2nd type:
<?php $myName = ' AA ';? >
The 3rd type:
<?php $MyName = ' AA ';? >
Experience sharing
Name, Age:
<?php/** variable name starts with $ * The name of the variable must be meaningful * variables cannot be named starting with a number, you can start with an underscore, $ and variable names cannot have spaces * operator symbols cannot appear in variable names: Subtraction * Other programming language variables may not appear in System keywords, But PHP can, because PHP has a $*/$name = "Beam bamboo"; $age =; $php = 40;echo $age;
Variable name area is only partially case
<?php/* $int and $int are case-sensitive, ECHO is case-insensitive */$int = ten; $INT = 20;echo $int, "<br>"; Echo $INT;
Camel name: One-and-three
<?php$onetwothree = 10;
A variable is used to temporarily store a container that is worth. These values can be numbers, text, or a much more complex permutation combination. is a simple tool for tracking almost all types of information.
PHP is a very weak type of language. In most programming languages, a variable can hold only one type of data, and the type must be declared before the variable is used, such as in the C language. In PHP, the type of the variable must be declared before the variable is used, for example, in the C language. In PHP, the type of the variable is usually not set by the programmer, rather, it is determined by the context at run time (that is, the value of the variable) based on the variable used. PHP does not require a variable to be declared before it is used, and you create it the first time you assign a value to the first variable.
PHP's variable declarations start with a $ character, followed by uppercase and lowercase letters, numbers, and underscores, but cannot start with a number.
<?php$a=100; Declare a variable A to give the integer 100$b= "string"; Declare a variable B, give the string string$c=true //Declare a variable C, give the Boolean value true$d=99.99; Declare a variable d to give the 99.99$key= point a $a; Declare a key variable and assign the value of a variable to $a= $b = $c = $d = "value" //Declare multiple variables at the same time and give the same value
You can use the function () to release the specified variable, the Isset () function detects whether the variable is set, empty () counts to check if a variable is empty
Declare multiple variables at the same time
<?php$a = $b = $c = $d =10;echo $a, echo "<br>", Echo $b, echo "<br>", Echo $c, echo "<br>"; echo $d; echo "& Lt;br> "; Var_dump (); Can print output variable type and content
<?phpvar_dump, $a =100;var_dump ($a);
The Isset () function detects if a variable is set
<?php$bool = Isset ($a); Var_dump ($bool); $a =; $bool = isset ($a); Var_dump ($bool); unset (); Delete a variable
<?php$a = 20;unset ($a), $bool = Isset ($a), Var_dump ($bool), empty () count check if a variable is empty, NULL returns True
<?php$a = $b = "; $c = 0; $d = null; $e ="; Var_dump (empty ($a)); Var_dump (Empty ($b)); Var_dump (Empty ($c)); Var_dump (em Pty ($d)); Var_dump (Empty ($e)); Var_dump (Empty ($f));
Back to the beginning of the article, let's see how to answer
Summarize
1, everyone likes no fixed pattern
2, the current PHP pair of variables are not case-sensitive (said PHP6 will be case-sensitive) so $myname= ' AA ', is written $myname= ' AA ', the effect is inconvenient but less readable than $my _name= ' AA ';
3, for case-sensitive language, generally recommend the use of "Hungarian notation"
A variable name consists of a variable type and several words that begin with an uppercase letter that denote the meaning of a variable.
Like what
$myname = ' AA ';
Just write it.
$sMyName = ' AA ';
and
$myname = 1;
Just write it.
$iMyName = 1;
4, for case-insensitive language, it is generally recommended that the variable name consists of a number of words that are connected by the meaning of the expression variable.
Like what
$myname = ' AA ';
Just write it.
$my _name= ' AA ';