The basic syntax for variable types

Learn the basic syntax is a little dull -> eroded

First, the acquaintance PHP script
1.PHP language tags
1) PHP start tag
<? PHP
2) PHP end tag
?>
<? PHP?>
3) Our final page is through html, css, js to demonstrate a dazzling interface
. 4) may be embedded in the code PHP html code anywhere, and can be embedded in any number
5) end of the file> end flag can be omitted?
2 command delimiter ";"
1) at the end of the statement to add some PHP on; indicates the end of a word, of course, do not need to remember possible, because once you
miss a semicolon, the program simply can not perform, will complain!
2) closing tag> is implied a;?
so> before? the PHP statement can be omitted;
3. Notes
1) multi-line comments
/ *
multiline comment
* /
2) single-line comment
// I am a single line comment
4. the process encountered blank
space, tab tabs, line feed these written our PHP code there is no problem
you can use these gaps to increase the readability of our code!
Second, variables
Overview:
for example child:
real life, we will be at home with cabinets to store our clothes, bags, books, etc. other things!
So we in the programming language which is not clothes, bags, books these concepts!
We only have data! So we have in the program where the data is stored in it? This is stored in our variable inside!

Variable is used for temporary (only exist during the operation of our program) stored value (data) of the container
STATEMENT 1. variable
declarations: it means to achieve inform, inform!
Before we get inside some programming languages such as C language variables to be advance notice prior statement about!
Note: Before using PHP variables inside our program does not require a declaration!

A variable for storing a number, a text string or array of data!
$ = Variable name data (values)
mean = mathematics which is' equal 'in our language program which it is not equal to the number, it is' assignment Fu '
destruction 2. variable
unset ($ variable name)
$ AND1 = 1;
unset ($ AND1); // destroy $ and variable
echo $ and1; // prompt an error, because the variable has been destroyed!
3. The naming of variables
1) the strict distinction between uppercase variable name
$ name, $ NAME, $ Name are different variables
2)
letter or underscore
! Take back any number of alphanumeric characters and underscores are

wrong naming:
$ 1name error point: start with a number of
$ n ame error point: the middle of whitespace characters
sum up: variable name can only contain alphanumeric characters and underscores and must begin with a letter or an underscore!

3) best not to use a few keywords as variable names (in other programming languages because there simply are not allowed)!
4. variable variable
// variable variable
$ abc = 'test'; // define a variable $ abc which kept the value of the Test
$$ abc = 'Sun Shengli'; // $ test = 'Sun Shengli';
echo $ the Test;

understand what you can!
The reference variable assignment
$ a = 1000;
/ * $ b = $ a; // corresponding to the value of $ a, copy and then assigned to the variable $ b * /
$ b = & $ a; // $ a is equivalent to an alias played, any of the operation, will affect the value of another variable!
$ B = 20 is;
echo $ a;
temporarily look on it!
three types of variables
Overview: variable type refer data stored in the variable type of
variable cabinet metaphor of clothes, books
PHP variable type to see relatively light, so we are more relaxed this lesson

1. Introduction variable type
1) bool (Boolean)
$ a = to true;
var_dump ($ a);
to the variable to store true or false, this variable is a boolean
2) int (integer)
to the variable to store integer, this variable is an integer variable it!
3) float (floating point type, also known as double)
to variables which kept decimals, then the variable is a floating-point data!
A = 1.1 $;
var_dump ($ A);
. 4) String (String)
String is a series string of characters together!
1 single quotes:
$ B = 1;
$ A = '$ bdwqd Test \' wqdqw ';
var_dump ($ A);
echo $ A;
in the definition of simple strings of single quotes when this method more efficient!
Two pairs of marks
$ B = 100;
$ A = '$ BST ...... TE';
$ A = "$ {B} ST TE ......";
var_dump ($ A);
echo $ A ;
3 delimiter
$ 200 is B =;
$ A = <<< WWW
dwqdqwdwq {B} $ dwqdqdqdqdwqdwqcwcfwefwefcscwecwefwdqwdqdefwefwefewfwe
WWW;
var_dump ($ A);
. 5) array (array)
after repeat!
6) object (an object)
after repeat!
7) resource (resource)
8) NULL
null variable does not represent a value that indicates the empty
variable direct assignment to null
declare a variable has not yet been assigned
Variable is destroyed unset function
$ A = 1111;
unset ($ A);
var_dump ($ A);

2. Variable type conversion
those too are unlikely to run in part controllable when it is best not to write code ! relates
cast:
$ A = 'Sun Shengli';
$ B = (int) $ A;
var_dump ($ A);
var_dump ($ B);

Guess you like

Origin www.cnblogs.com/xiaowie/p/11540117.html