PHP introductory training tutorial PHP variables and constants







    1. The basic syntax format of PHP5.4

  1. The delimiter of PHP

  $php=true; //Semicolon end statement

  if($php){

  echo "true"; //Semicolon end statement

  } //Brace end statement

  ?>

  2. PHP comments and syntax marks (Brothers PHP training www.lampbrother.net

)

  (1), single-line comments // Comments from C++# Comments from C language

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

  3. Function usage 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 (.. ..) general character // usage of PHP5.4

  2. Variables and data types of

  variables in PHP5.4 Variables start with a dollar sign "$", followed by an identifier. The identification string only consists of letters, numbers, and underscores and cannot start with numbers.

  $php=true; //Semicolon ends the statement

  if($php){

  echo "true"; //Semicolon ends the statement

  } //The brace ends the statement

  $url="blog.csdn.net/dawanganban"; // define variable

  echo $url;

  unset($url); //Delete a variable url

  echo $url;

  ?>How

  variables are named

  (1) Directly connect words between words

  $titlekeyword

  (2) Connect words with underscores

  $title_keyword

  (3) The first letter between words is capitalized (camel case) The data types of

  $titleKeyword

  PHP are as follows:

  (1) String (String): the content within single quotation marks (simple quotation marks) or double quotation marks (functional quotation marks)

  (2) integer (integer) : -2^32 < n < 2^32-1

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

  (4) Boolean (boolean) true or false

  (5) Array (Array)

  (6)Object (Object)

  class Person{

  public $userName="Sunshine Xiaoqiang";

  public function getMsg(){

  echo "Name is:".$this->userName;

  }

  }

  $p=new Person() ;

  $p->getMsg();

  ?>

  (7) Resource type (Resouce) System data resource

  Resource is a special data type that cannot directly obtain variables and needs to be accessed through special functions:

  database access must be accessed through the Mysql function library, Mysqli function library or PDO function library implementation.

  File access must be implemented through the FileSystem library.

  Directory operations must be implemented through the Directory library.

  Image manipulation must be implemented through the GD library.

  (8) Null value (NULL)

  3. System constants and custom constants of PHP5.4

  Constants cannot change data during program execution, and the scope of constants is global. Constants are named like variables, but without the "$" sign. A valid constant starts with a letter or an underscore. Generally, constants in PHP are capital letters and are divided into system constants and custom constants.

  Example of system constants:

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

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

  __CLASS__ class name A constant is defined by the define() function

  in PHP, and its syntax format is:

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

  name: the name of the constant

  value: the value of the constant

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

  define("COLOR", "red"); //Define a constant COLOR, the value is red

  echo COLOR."

  "; //Output the value of the constant COLOR

  Variable variable

  $a="b"

  $$a="123" //Variable variable

  echo $b;

  The output result is: 123

  To output variables in the string, use double quotes

  $a=50;

  //echo 'I have $a yuan"; single quote

  echo "I have $a yuan RMB";

  There are more escape characters that can be executed in double quotation marks, such as \n \t \r to

  judge the data type

  $a="-5";

  //$a=-5;

  var_dump($a);


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486655&siteId=291194637