PHP Mobile Internet Development Notes (2)--variables and constants
First, the basic grammatical format of PHP5.4
1. PHP Separator
View Source print?
1.
$php
=true;
//分号结束语句
2.
if
(
$php
){
3.
echo
真
;
//分号结束语句
4.
}
//大括号结束语句
5.
?>
2. PHP comments and syntax identifiers
(1), single line comment//note from C + + Note
(2), multiline comment/* */Note from C language
3, the function of the use of the format
(1) Return value function name ()
(2) Return value function name (parameter, parameter)
(3) Function name (parameter, parameter, return variable)
(4) The return value function name (.. .. ) General character//PHP5.4 usage
The data types of variables and variables of PHP5.4
The variable is preceded by a dollar sign "$," and is followed by an identifier. The identity string consists of letters, numbers, underscores, and cannot begin with a number.
View Source print?
01.
$php
=true;
//分号结束语句
02.
if
(
$php
){
03.
echo
真
;
//分号结束语句
04.
}
//大括号结束语句
05.
06.
$url
=
blog.csdn.net/dawanganban
;
//定义变量
07.
echo
$url
;
08.
unset(
$url
);
//删除一个变量url
09.
echo
$url
;
10.
?>
How variables are named
(1) Direct connection between words
$titlekeyword
(2) Connect the words with an underscore
$title _keyword
(3) initial capital (hump) between words
$titleKeyword
The data types of PHP are as follows:
(1) String: The contents of single quotation marks (simple quotation marks) or double quotation marks (functional quotes)
(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)
View Source print?
01.
class
Person{
02.
public
$userName
=
阳光小强
;
03.
public
function
getMsg(){
04.
echo
姓名为:
.
$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 type of data that cannot be directly derived and needs to be accessed through a specialized function:
Database access must be implemented through the MySQL function library, the MYSQLI function library, or the PDO function library.
File access must be implemented through the FileSystem function library.
Directory operations must be implemented through the Directory function library.
Image operations must be implemented through the GD function library.
(8) null value (NULL)
System constants and custom constants for PHP5.4
Constants cannot change data during program execution, and the scope of constants is global. The name of a constant is similar to a variable, except for the $ symbol. A valid constant starts with a letter or an underscore, and generally in PHP, the constants are uppercase and are divided into system constants and custom constants.
Example System constants:
__file__ default constant, refers to the PHP program file name and path
__line__ default constant, which is the number of lines in a PHP program
Name of the __class__ class
In PHP, you define a constant by using the Define () function, which has 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 name of the constant is case sensitive. True is not case-sensitive, and if set to false is case-sensitive, the default value is False.
View Source print?
1.
define(
COLOR
,
red
);
//定义一个常量COLOR,值为red
2.
echo
COLOR.
3.
;
//输出常量COLOR的值
Variable variable
View Source print?
1.
$a
=
b
2.
$
$a
=
123
//可变变量
3.
echo
$b
;
Output Result: 123
To output a variable in a string, use double quotation marks
View Source print?
1.
$a
=50;
2.
//echo '我有$a元人民币; 单引号
3.
echo
我有$a元人民币
;
You can perform more of the signifier characters in double quotes, such as
Judging data types
View Source print?
1.
$a
=
-5
;
2.
//$a=-5;
3.
var_dump(
$a
);
http://www.bkjia.com/PHPjc/885677.html www.bkjia.com true http://www.bkjia.com/PHPjc/885677.html techarticle PHP Mobile Internet Development Notes (2)--variables and constants one, PHP5.4 basic syntax Format 1, PHP splitter view source print? 1. $php =true; Semicolon concluding sentence 2. if ($php ...