3 Basic PHP syntax

Source: Internet
Author: User

Start with <?php and end with?>

Semicolon

Function Execution statement: must add a semicolon. is to add a semicolon to the code statement.

Code Structure statement: Do not add semicolons. Just like the function {} curly braces are not appended

Comments

...... Single-line Comment

/*/... * * Multi-line Comments (multiple lines of comments cannot be nested in multiple lines of comment)

#...... Script comments

/**......*/Document Comments

Note: It is often customary to write comments to the top or right of the code, i.e. write the comments before writing the code

variables

A variable is a container that is temporarily stored

PHP is a weak type of language

The variable starts with a $ symbol followed by a letter, a number, an underscore, but not a number.

<php  $a = "Hello";   $b = +;   $c =true;? >

Variable variable

$a = "Hello";

$ $a = "PHP"; Actual: $ $a is $ ($a), i.e. $hello

Note: You cannot add other characters between two $ characters and must be close to, such as $my $ A = = $myhello This does not exist

<?  $a= "Hello"; $$a= "php"; Var_dump ($a);  Hellovar_dump($$a);  PHPvar_dump($hello
?>

Ways to manipulate variables

unset () Delete variable

Isset () detects if the variable is set

Empty () detects if the variable is null

Var_dump () detects the variable type and value, which is the type and value of the input variable

<?PHP$a= "Hello"; $b=""; Var_dump($a); Var_dump($b); Var_dump(Empty($b));//$b is empty, empty ($b) returns True   Var_dump(isset($c));//$c Undefined, isset ($c) returns false    unset($b);//delete variable?>

A reference to a variable

& Symbols

<?PHP$a=10;$b=&$a;Echo $a." </br> "; Echo $b." </br> ";//$b the same address as $ A$a=100;Echo $a." </br> ";// -Echo $b." </br> ";// -$b=200;Echo $a." </br> ";// $Echo $b." </br> ";//200

From the above can be seen, re-assign one of the values, the other changes
?>

1. Only variables have addresses

$b = &10; 10 is not a variable, error

2. One variable changes and the value of the other variable changes

3. When using unset (), if there is a referential relationship, deleting a variable simply deletes the reference relationship

4. A variable can have only one reference address, if you give it two addresses, then the following address overwrites the previous address, the reference relationship of the preceding address is broken

<?PHP//the address of a variable to two or more variables, changing one of the other full changes$a=10;$b=&$a;$c=$a; or$a=10;$b=&$a;$c=$b;//two different addresses to the same variable, after giving the overwrite first given, first give the broken reference relationship$a=10;$c=111;$b=&$a;$b=$c//b before receiving the address of a, now receive the address of C, whichever is later?>

3 Basic PHP syntax

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.