Home  >  Article  >  Backend Development  >  PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:18:06753browse

PHP Mobile Internet Development Notes (2) - Variables and Constants

1. Basic syntax 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 markers

(1), single line comment //Comment from C++ #Comment from C language

(2), multi-line comments /* */ Comments from C language

3. Function usage format

(1) Return value function name()

(2) Return value function name (parameter, parameter)

(3) Function name (parameters, parameters, return variables)

(4) Return value function name (.. ..) universal character // Usage of PHP5.4

2. PHP5.4 variables and variable data types

A variable starts with a dollar sign "$," followed by an identifier. The identification string only consists of letters, numbers, and underscores and cannot start 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 to name variables

(1) Direct connection between words

$titlekeyword

(2) Use underlines to connect words

$title_keyword

(3) Capitalize the first letter between words (hump case)

$titleKeyword

PHP’s data types are as follows:

(1) String: Content within single quotes (simple quotes) or double quotes (functional quotes)

(2) Integer: -2^32

(3) Floating point character (float or double) 1.8E+308 (1.8 x 10^308)

(4) boolean true or false

(5)Array

(6) 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.?> PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

(7) Resource type (Resouce) System data resource

Resource is a special data type. Variables cannot be obtained directly and need to be accessed through special functions:

Database access must be achieved 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 implemented through the Directory function library.

Image operations must be implemented through the GD function library.

(8)NULL

3. System constants and custom constants of PHP5.4

Constants cannot change data during program execution, and the scope of constants is global. The naming of constants is similar to variables, except without the "$ symbol. A valid constant starts with a letter or underscore. Generally, constants in PHP are capital letters and are divided into system constants and custom constants.

System constant example:

__FILE__ default constant, refers to the PHP program file name and path

__LINE__ is the default constant, which refers to the number of lines in the PHP program

__CLASS__ The name of the class

In PHP, define a constant through the define() function. Its syntax format is:

bool define(string $name, mixed $value [, bool case_$insensitive])

name: the name of the constant

value: value of constant

insensitive: Specifies whether the constant name is case-sensitive. If set to true, it is case-insensitive; if set to false, it is case-sensitive. The default value is false.

view source print? 1.define(COLOR, red); //定义一个常量COLOR,值为red 2.echo COLOR. 3.; //输出常量COLOR的值

Variable variables

view source print? 1.$a=b 2.$$a=123 //可变变量 3.echo $b; The output result is: 123

Use double quotes when outputting variables in a string

view source print? 1.$a=50; 2.//echo '我有$a元人民币; 单引号 3.echo 我有$a元人民币; There are more escape characters that can be executed in double quotes, such as

Determine data type

view source print? 1.$a=-5; 2.//$a=-5; 3.var_dump($a);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/885677.htmlTechArticlePHP Mobile Internet Development Notes (2) - Variables and Constants 1. Basic syntax format of PHP5.4 1. PHP delimiter view source print? 1. $php =true; //Semicolon ends statement 2. if ( $php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn