PHP

1. Basic

  1. Begins with <?php and ends with ?>

    1
    2
    3
    <?php
    echo strlen("Hello, World!");
    ?>
  2. Comments

    // and # for a single line.
    /* */ for block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
    // Single line Comment.
    # Also single line.
    /*
    And comment block,
    Cross
    multiple
    lines.
    */
    ?>
  3. Case Sensitivity

  • All the function() class and the key word is NOt cAse SenSiTivE

    1
    2
    3
    4
    5
    6
    <?php
    // They all do the same things.
    ECHO "Hello World!<br>";
    echo "Hello World!<br>";
    EcHo "Hello World!<br>";
    ?>
  • But the $variable is CASE SENSITIVE

    1
    2
    3
    4
    5
    6
    7
    <?php
    // Only the FIRST statement can do the right output.
    $color="red";
    echo "My car is " . $color . "<br>";
    echo "My house is " . $COLOR . "<br>";
    echo "My boat is " . $coLOR . "<br>";
    ?>

2. Variable

  1. The $variable begins with the $ char.

    1
    2
    3
    4
    5
    6
    <?php
    // They are all variables
    $x = 5;
    $txt = "Hello, World!";
    $y = 10.5;
    ?>
  2. Weak Type

PHP is an weak type language, you do not have to announce the type when you create the variable
As the above, $x is an int, $txt is an string and $y is an float

  1. Scope
  • Local
    - The variable can only be konwn inside the function or the current statement
  • Global
    - The variable can be konwn at any where
  • Static
    - The variable whose value can be maintain
  • 本文作者: Wafer Li
  • 本文链接: https://wafer.li/PHP/PHP/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!