PHP Mobile Internet development variables and constants

Source: Internet
Author: User
[Introduction] PHP5 4 basic syntax Format 1, PHP separator 2, PHP comments and syntax identification (1), single-line comment from C + + comments from

1. PHP Separator


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

A 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.

    $php =true;  Semicolon concluding sentence      if ($php) {          echo "true";    Semicolon concluding sentence      }             //Curly brace concluding sentence            $url = "Blog.csdn.net/dawanganban";  Define the variable      echo $url;       Unset ($url);   Delete a variable URL      echo $url;  ? >

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)

Class person{public      $userName = "Sunshine cockroach";      Public Function getmsg () {          echo "name:". $this->username;      }  }  $p =new person ();  $p->getmsg ();    ? >


(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)

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 that it does not have a "$" 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.

Define ("COLOR", "Red");  Defines a constant COLOR with a value of red  echo COLOR. "";       The value of the output constant color

Variable variable

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

Output Result: 123

To output a variable in a string, use double quotation marks

$a =50;  Echo ' I have a $ A yuan ';    Single quote  echo "I have $ A yuan";

You can execute more of the signifier characters in double quotes, such as \ t \ r

Judging data types

$a = "5";  $a =-5;  Var_dump ($a);

First, the basic grammatical format of PHP5.4

1. PHP Separator

    $php =true;  Semicolon concluding sentence      if ($php) {          echo "true";    Semicolon concluding sentence      }             //Curly brace concluding sentence  ?>

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

A 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.

    $php =true;  Semicolon concluding sentence      if ($php) {          echo "true";    Semicolon concluding sentence      }             //Curly brace concluding sentence            $url = "Blog.csdn.net/dawanganban";  Define the variable      echo $url;       Unset ($url);   Delete a variable URL      echo $url;  ? >
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)

Class person{public      $userName = "Sunshine cockroach";      Public Function getmsg () {          echo "name:". $this->username;      }  }  $p =new person ();  $p->getmsg ();    ? >

(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 that it does not have a "$" 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.

Define ("COLOR", "Red");  Defines a constant COLOR with a value of red  echo COLOR. "";       The value of the output constant color

Variable variable

$a = "B"         $ $a = "123"  //variable variable  echo $b;
Output Result: 123

To output a variable in a string, use double quotation marks

$a =50;  Echo ' I have a $ A yuan ';    Single quote  echo "I have $ A yuan";
You can execute more of the signifier characters in double quotes, such as \ t \ r

Judging data types

$a = "5";  $a =-5;  Var_dump ($a);

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.