PHP mobile internet development notes (2 )?? Basic syntax format of variables and constants 1 and PHP5.4
1. PHP delimiter
View source
Print?
1. $ php = true; // semi-colon concluding remarks
2. if ($ php ){
3. echo "true"; // semi-colon concluding remarks
4.} // braces
5.?>
2. PHP comments and syntax identifiers
(1) single line comment // comments from C ++ # Comments from C language
(2) multi-line comments/**/comments from C language
3. function format
(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 operator // PHP5.4 usage
2. data types of PHP5.4 variables and variables
A variable starts with a dollar sign "$" and is an identifier after "$. A string can contain letters, numbers, and underscores and cannot start with a number.
View source
Print?
01. $ php = true; // semi-colon concluding remarks
02. if ($ php ){
03. echo "true"; // semicolon concluding remarks
04.} // braces
05.
06. $ url = "blog.csdn.net/dawanganban"; // define the variable
07. echo $ url;
08. unset ($ url); // delete a variable url
09. echo $ url;
10.?>
Variable naming method
(1) direct connection between words
$ Titlekeyword
(2) words are connected by underscores.
$ Title_keyword
(3) uppercase letters (hump) between words)
$ TitleKeyword
PHP Data types are as follows:
(1) String: content in single quotation marks (simple quotation marks) or double quotation marks (function quotation marks)
(2) integer:-2 ^ 32 <n <2 ^ 32-1
(3) floating point character (float or double) 1.8E + 308 (1.8x10 ^ 308)
(4) boolean (boolean) true or false
(5) Array)
(6) Object)
View source
Print?
01. class Person {
02. public $ userName = "Sunshine Xiaoqiang ";
03. public function getMsg (){
04. echo "name:". $ this-> userName;
05 .}
06 .}
07. $ p = new Person ();
08. $ p-> getMsg ();
09.
10.?>
(7) resource type (Resouce) system data resources
A resource is a special data type and cannot directly obtain variables. it needs to be accessed through special functions:
Database access must be implemented through the Mysql function library, Mysqli function library, or PDO function library.
File access must be implemented through the FileSystem function library.
Directory operations must be performed through the Directory function library.
Image operations must be implemented through the GD function library.
(8) NULL (NULL)
III. PHP5.4 system constants and custom constants
Constants cannot change data during program execution, and their scopes are global. The constant name is similar to the variable name, but it does not contain the "$" symbol. A valid constant starts with a letter or underscore. generally, constants in PHP are uppercase letters and can be divided into system constants and custom constants.
Example of system constants:
_ FILE _ default constant, indicating the PHP program FILE name and path
_ LINE _ default constant, indicating the number of lines in the PHP program
_ CLASS name
The define () function is used in PHP to define a constant. the syntax format is:
Bool define (string $ name, mixed $ value [, bool case _ $ insensitive])
Name: constant name
Value: constant value
Insensitive: specifies whether the constant name is case sensitive. If it is set to true, it is case insensitive. if it is set to false, it is case sensitive. the default value is false.
View source
Print?
1. define ("COLOR", "red"); // defines a constant COLOR with a value of red.
2. echo COLOR ."
3. "; // the COLOR value of the output constant.
Variable
View source
Print?
1. $ a = "B"
2. $ a = "123" // variable
3. echo $ B;
Output result: 123
Double quotation marks are used to output variables in strings.
View source
Print?
1. $ a = 50;
2. // echo 'I have $ a RMB "; single quotes
3. echo "I have $ a RMB ";
In double quotation marks, more conversion characters can be executed, such as \ n \ t \ r.
Determine data type
View source
Print?
1. $ a = "-5 ";
2. // $ a =-5;
3. var_dump ($ );