A _php tutorial on the Essentials of PHP code

Source: Internet
Author: User
Tags echo command

The main points of PHP code analysis a


One. The difference between the post and the GET request mode:

1. Request form is different: Get request is to send data angle to the server at the end of the URL, post is sent to the server in a separate message, in the background.

2. Send length is different: GET request maximum data volume is 2k,post request theoretically unlimited, you can set its size in the configuration file.

3. Security: Because the Get mode data is appended to the URL and sent to the server, get security is low.

4. Application scenario: Get is used when data is simple and security requirements are not high, otherwise, use post.


Two. Declaration and use of constants:

Define (' PAI1 ', 3.1415) const PAI2 = 3.1415;echo PAI1, pai2;define (' ^_^ ', ' smiley face ');//This form cannot be used to output this variable with the Echo ^_^, with a function to echo Constant (' ^_^ ');

Three. Scope of variables:

Personally, there are three types of scopes in PHP

1. An external scope refers to a range outside the function body within a script, which is declared in this area, and is available externally, but cannot be used inside that function.

2. Internal scope, refers to a script within the scope of the body of the function, declared in this area of the variable, internally available, but not visible externally.

3. The Hyper global scope can be used anywhere in any script, such as within the test function of the a.php script or outside of the function, as well as in the b.php script.

How can you make a variable available internally or externally within an external declaration? --global Key

$v 1 = ' global V1 ';        Func1 ();        function Func1 () {            //echo $v 1;//undefined            global $v 1;            echo ' function inner VARs v1: ', $v 1;        }        Echo ' The following is an example of using external declarations inside a function
'; function Func2 () { global $v 2;//comment, output $v2 in global error $v 2 = ' function inner v2 '; } Func2 (); echo $v 2;

Four. Operators

% operator: the symbol of the calculated result is the same as the first operand symbol

& Reference operators:

$v 3 = 1;        $v 4 = & $v 3;        Unset ($v 3); Unset will be destroyed after the variable, can not access $v3        //echo $v 3;//unset again visit $v3 will error
And OR operator:

With && | | Same function, only lower priority (= lower)

function Func1 () {return false;} $a = func1 () or Die (' func1 execution return value is false '); $a = func1 () | | | Die (' Func1 execution return value is false ');


Five. Echo and Print differences

It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two:
In the Echo function, you can output multiple strings at the same time, and in the print function you can only output one string at a time. At the same time, the Echo function does not require parentheses, so the echo function is more like a statement than a function.

Echo and print are not functions, but language constructs, so parentheses are not required. The difference between them is:
(1) Echo can output multiple strings, like this:
Echo ' A ', ' B ', ' C ';
If you have to add parentheses, note that echo (' A ', ' B ', ' C ') is wrong and should be written as:
Echo (' A '), (' B '), (' C ');
It does not behave like a function, so it cannot be used in the context of a function

(2) Print can only output a string, it may behave like a function, for example, you can use the following:
$ret = print ' Hello world ';
All of it can be used in more complex expressions.


In addition, ECHO's efficiency is relatively fast ~
echo command differs from print command
When used, echo can output multiple variables separated by commas, while print can only output one variable


The Echo function differs from the print function.
Echo () No return value, same as echo command
Print () has a return value, success, return to 1,false, return to 0. Therefore, print is slower than echo, but can be applied to more complex expressions.


Six. Isset and empty differences
The Isset function is used more in development to determine whether the variable exists or whether it opens up memory.
The empty function is not only to determine if the value is null, but also when the secondary variable is undefined, that is, when no memory is opened, it returns false, that is, the empty function needs to be true for the isset to be null.

Seven. Switch can support shaping, floating-point type, string, can also support array, Boolean type, allow no default

$bol = true;        $bol = false;        $bol = [1,   2, 3];        Switch ($bol) {case            0:                Echo ' 0
'; break; Case: Echo ' 10
'; break; Case-1: Echo '-1
'; break; case [All in all]://array echo ' empty array
'; break; Case 0: Echo ' 0
'; break; } When a bool type, true when the case value is true, False when the value is false after the cases output, you can run the code, you can


http://www.bkjia.com/PHPjc/969600.html www.bkjia.com true http://www.bkjia.com/PHPjc/969600.html techarticle key points of PHP code analysis one by one. The difference between post and GET request: 1. The request form is different: The GET request is to send the data angle to the server at the end of the URL, the post is in a separate message form ...

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