PHP mobile internet development variables and constants

Source: Internet
Author: User
PHP100 is the first professional website in China to share PHP resources. It also provides a PHP Chinese communication community. For PHP study researchers: The latest PHP information, original content, open source code and PHP video tutorials and other related content. [Guide] 1. basic syntax format of PHP5 4 1. PHP delimiter 2. PHP annotation and syntax identifier (1). single line annotation comes from C ++ annotation

1. PHP delimiter


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

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.

$ Php = true; // semi-colon concluding remarks if ($ php) {echo "true"; // semi-colon concluding remarks} // braces concluding remarks $ url = "blog.csdn.net/dawanganban "; // define the variable echo $ url; unset ($ url); // delete a variable url echo $ url;?>

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)

Class Person {public $ userName = "Sunshine Xiaoqiang"; 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 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)

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.

Define ("COLOR", "red"); // defines a constant COLOR with the value of red echo COLOR. ""; // outputs the value of the constant COLOR.

Variable

$ A = "B" $ a = "123" // variable echo $ B;

Output result: 123

Double quotation marks are used to output variables in strings.

$ A = 50; // echo 'I have $ a Yuan Renminbi "; single quotes echo" I have $ a Yuan Renminbi ";

In double quotation marks, more conversion characters can be executed, such as \ n \ t \ r.

Determine data type

$a="-5";  //$a=-5;  var_dump($a);

I. basic syntax format of PHP5.4

1. PHP delimiter

$ Php = true; // semi-colon concluding remarks if ($ php) {echo "true"; // semi-colon concluding remarks} // braces concluding remarks?>

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.

$ Php = true; // semi-colon concluding remarks if ($ php) {echo "true"; // semi-colon concluding remarks} // braces concluding remarks $ url = "blog.csdn.net/dawanganban "; // define the variable echo $ url; unset ($ url); // delete a variable url echo $ url;?>
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)

Class Person {public $ userName = "Sunshine Xiaoqiang"; 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 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.

Define ("COLOR", "red"); // defines a constant COLOR with the value of red echo COLOR. ""; // outputs the value of the constant COLOR.

Variable

$ A = "B" $ a = "123" // variable echo $ B;
Output result: 123

Double quotation marks are used to output variables in strings.

$ A = 50; // echo 'I have $ a Yuan Renminbi "; single quotes echo" I have $ a Yuan Renminbi ";
In double quotation marks, more conversion characters can be executed, such as \ n \ t \ r.

Determine data type

$a="-5";  //$a=-5;  var_dump($a);

These are the variables and constants of PHP mobile Internet development. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.