PHP mobile Internet Development notes (2) -- variables and constants
I. Basic syntax format of PHP5.4
1. PHP delimiter
View source print?
1.
$php
=true;
// Semicolon concluding remarks
2.
if
(
$php
){
3.
echo
True
;
// Semicolon 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;
// Semicolon concluding remarks
02.
if
(
$php
){
03.
echo
True
;
// Semicolon concluding remarks
04.
}
// Braces
05.
06.
$url
=
blog.csdn.net/dawanganban
;
// Define variables
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
);
// Define a constant COLOR with the value of red
2.
echo
COLOR.
3.
;
// Output constant COLOR value
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
Determine Data Type
View source print?
1.
$a
=
-5
;
2.
//$a=-5;
3.
var_dump(
$a
);