PHP Syntax (i): Basics and variables

Source: Internet
Author: User
Tags closing tag
Recently there is a H5 project needs, the need for service side, after the investigation decided to use PHP to implement an HTTP server, so began to review PHP syntax, by the way to record the key points, so that you can revisit at any time. The contents of the PHP manual are compiled from W3school.

What is PHP?

  • PHP is the acronym for "PHP Hypertext Preprocessor"
  • The PHP code executes on the server, and the result is returned in plain text to the browser
  • PHP files can contain text, HTML, CSS, and PHP code
  • The suffix of the PHP file is ". php"
  • The PHP script can be placed anywhere in the document.
  • PHP files usually contain HTML tags and some php script code.
  • PHP Basic Syntax

  • Script with End
  • Statement ends with a semicolon (;).
  • The closing tag of a code block also automatically indicates a semicolon (so you don't have to use a semicolon in the last line of the PHP code block).
  • Or # indicates a single line comment
  • /**/is a multiline comment
  • Variable case Sensitivity
  • user-defined functions, classes, and keywords are insensitive to case sensitivity (for example, if, else, Echo, and so on).
  • PHP variables

  • Variable weak type
  • The variable begins with a $ symbol followed by the name of the variable, such as $x = 5;
  • Variables declared outside the function have Global scope and can only be accessed outside of the function.
  • Variables declared inside a function have a local scope and can only be accessed inside the function.
  • The global keyword is used to access variables within the function. To do this, use the Global keyword before (inside the function) variable:
  • Example 1:

     
      

    Example 2:

     
      

    PHP Static Keywords

    PHP Static Keywords
    Typically, all variables are deleted when the function finishes/executes. However, sometimes I need to not delete a local variable. Achieving this requires a bit of further work.
    To do this, use the static keyword when you first declare a variable:

     
      

    Then, whenever the function is called, the information stored by the variable is the information contained in the last Call of the function.
    Note: The variable is still a local variable of the function.

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