The basic grammatical format of PHP5.4
1, PHP's separator
$php =true; Semicolon closing sentence
if ($php) {
echo "true"; Semicolon closing sentence
} //Curly brace closing sentence
?>
2, PHP annotation and syntax identification
(1), Single-line comments//from C + + comments # from the C language annotation
(2), multiline annotation/* * from the C language annotation
3, the use of the format of the function
(1) Return value function name ()
(2) Return value function name (parameter, parameter)
(3) Function name (parameter, parameter, return variable)
(4) Return value function name (... .. ) Common character//PHP5.4 usage
Two, PHP5.4 variables and variables of the data type
The variable is preceded by a dollar sign "$" and an identifier after "$". The identity string is made up of letters, numbers, underscores, and cannot begin with a number.
$php =true; Semicolon closing sentence
if ($php) {
echo "true"; Semicolon closing sentence
} //Curly brace closing sentence
$url = "Blog.csdn.net/dawanganban"; Defines the variable
echo $url;
Unset ($url); Delete a variable URL
echo $url;
? >
How to name a variable
(1) Direct connection between words
$titlekeyword
(2) The words are connected by an underscore
$title _keyword
(3) Capitalize the first letter (hump) between words
$titleKeyword
The data types of PHP are as follows:
(1) String: Single quotation mark (simple quotation mark) or double quotation mark (function quotation mark) contents
(2) Integral type (integer): -2^32 < n < 2^32-1
(3) floating-point character (float or double) 1.8E+308 (1.8 x 10^308)
(4) Boolean (Boolean) True or False
(5) Arrays (array)
(6) Objects (object)
Class person{public
$userName = "Sunshine cockroach";
Public Function getmsg () {
echo "name:". $this->username;
}
}
$p =new person ();
$p->getmsg ();
? >
(7) resource type (resouce) system data Resources
A resource is a special data type that cannot be directly obtained, and needs to be accessed through specialized functions:
Database access must be implemented through MySQL function library, mysqli function library, or PDO function library.
File access must be implemented through the FileSystem function library.
Directory operations must be implemented through the Directory function library.
The image operation must be implemented through the GD function library.
(8) null value (NULL)
Three, PHP5.4 system constants and custom constants
Constants cannot change data during program execution, and the scope of the constants is global. The name of a constant is similar to a variable, except that the "$" symbol is not. A valid constant begins with a letter or an underscore, typically in PHP, where the constants are uppercase and are divided into system constants and custom constants.
System Constants Example:
__file__ default constant, refers to the PHP program file name and path
__line__ default constant, refers to the number of lines of PHP program
Name of the __class__ class
In PHP, you define a constant by using the Define () function, which is in the following syntax format:
BOOL Define (String $name, mixed $value [, BOOL case_$insensitive])
Name: Names of constants
Value: Values of constants
Insensitive: Specifies whether the constant name is case-sensitive. If set to true, it is case-insensitive, and if set to false, it is case-sensitive and the default value is False.
Define ("COLOR", "Red"); Defines a constant color with a value of red
echo color. "
"; Output the value of a constant color
Variable variable
$a = "B"
$ $a = "123" //variable variable
echo $b;
The output is: 123
To output a variable in a string using double quotes
$a =50;
Echo ' I have $a yuan '; Single quote
echo "I have $a yuan";
More characters can be executed in double quotes, such as \ t \ n \ r
Determining data types
$a = "-5";
$a =-5;
Var_dump ($a);