php beginner

php syntax

1. Form

    Standard form <?php

                               ---Here is the php code-----

                     ?>

    Standard Form 2 <script language="php">

                               ---Here is the php code-----

                     </script>

    Short tag form <?

                               ---Here is the php code-----

                       ?> (this form is not recommended, this form depends on a setting in php.ini: short open tag = On) 

    The closing tag can sometimes be omitted (--------------Don't omit the closing tag for good habits------------)

2. Grammatical form

    Mainly refers to the variable name case sensitive

    Constants are usually also differentiated, but constants can also be set to be indistinguishable by themselves (not recommended)

    But the function name does not distinguish

    The keywords used in the system are not case sensitive, such as if, else, for

3. Variables

    A variable contains a name and a value "identifier".

 

 

 When we use the variable name $v1 in the code, we use the data value of "1"; for example: echo $v1; //output 1

 When we perform a certain "operation" on the variable $v1 in the code, that is, the operation on this value 1: for example: $v1++; //Increase the value of 1 by 1, the result is data city 2.

 -------- Usually in the syntax of "can appear" variables, as long as the $ sign appears, followed by the next character, it will be recognized as a variable, even if the variable does not exist.

4. Basic use of variables

  Defining a variable (assignment): Directly assigning a value to a variable is a definition.

    Does not support the "define but not assign" syntax in js,

    In other words, the first time a variable is assigned a value, the variable is defined.

  

Value: In all statements that require a variable value, the value of the variable will be obtained. Commonly include:

    

  • Output: echo $v1; //Get the value of $v1 and output
  • Assign other variables $v2 = $v1; //Get the value of $v1 and assign it to $v2
  • Participate in the operation: $v3 = $v1 + 3; //Get the value of $v1 and add it to 3. . . .

 

Guess you like

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