PHP Full stack Development (iv): PHP Learning (1. Basic syntax)

Source: Internet
Author: User
Tags php language

The PHP script executes on the server and returns the results of plain HTML to the browser.

It sounds very powerful, so PHP is the server-side language. HTML is the front end.

The default file name extension for PHP files is ". php"

So PHP files usually contain HTML tags and some PHP script code.

PHP script starts with <?php> and ends with?>.

PHP scripts can be placed anywhere in the PHP file.

<! DOCTYPE html>  echo "Hello world!"  ?> </body> 

Each line of PHP code must end with a semicolon, which is similar to the C language.

PHP has two kinds of annotation methods, one is a single line comment//

One is multiline comment/* */

Even the notes and the C language are the same.

Both the PHP statement and the PHP variable are case-sensitive.

The PHP variable starts with the dollar sign $, and the rest of the naming conventions are similar to the C language.

The PHP language, like the scripting languages of Perl and Python, is just as good as using variables, without declaring its type.

This is really great.

<?  $x=5$y=10function  myTest () {     global $x,$y;      $y=$x+$yecho$y//

The PHP language has global variables, and the variables defined outside the function are global variables, such as $x and $y.

Then to use them inside the function, you must use the Global keyword to declare that these two things are global variables before they can be used, otherwise the use of the OH.

This must be remembered, because it is very useful, because we often need to use global variables when writing programs with functions.

Let's take another look at the code:

<?  function  myTest () {     static$x=0;      Echo $x ;      $x+ +

See here we see there is a static stuff. What is this, called a static variable?

Here we see that the static variable is 0 when it is first declared.

And what will be the result of our execution? It's going to be 012.

Originally in the function, preceded by a static variable, the function is not destroyed after the end of the run, will continue to retain.

When the function is executed again, the value after the last execution of the function is inherited.

It should be noted here that the initial value must be assigned at the time of Declaration, and who knows what you are if you do not assign an initial value.

PHP Full stack Development (iv): PHP Learning (1. Basic 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.