Getting Started with PHP Basics (ii)---prerequisites!

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators getting started with php php basics php script knowledge base

Tag:tor    anti-    mask     flexible     arithmetic operators      Anchor points    bmc   splay    advantages    

Objective

In the previous chapter, we initially learned about PHP's web base and the basics of PHP, and continue to share more knowledge about PHP today.

Theoretical knowledge may seem more boring, but our practice (knocking at code) is inseparable from it.

Only by combining theory with practice can we achieve more functions with minimal code.

* * This chapter key words : operators; variable variables; access symbols; branches and loops; Process Control Statement Goto.

Let's take a look at the operators in PHP and more about PHP Knowledge Base :

an operator

1, arithmetic operators:+-*/% + +--


2, assignment operator:= + = = *=/=%=. = (Connection string)


3. Comparison operators:> < >= <= = = = = = = = <>,! = ==


= =: Requires equal value, without data type equality


= = = requires value and data type, must be equal


! =: Compare values only, value equal to False


!==: Compare values and types, both values and types are equal to False


4. Logical operator:and/&& or/| | not/! Xor

&& | | A short circuit occurs when the operation is performed:
The right side is no longer executed when the left side is able to determine the result!! (The result is false when the left side of the && is false; | | The result is true when the left side is true)

XOR: Logical XOR. There is only one pair on both sides, the result is true, both sides are true or the same is false, and the result is false.


5, Bitwise operators:

Convert the 10 binary to 2 and then the operation.

&: Bitwise AND, turn into binary, two are 1, the result is 1
|: Bitwise OR, after switching to binary, there is a 1, which is 1
^: Bitwise XOR, after turning into binary, the two are different 1, two are 1, or both are 0, the result is 0.
~: Bitwise reversed, converted to binary number, all digits reversed. 1--->0 0--->1
<<: Left shift: After turning into binary, left a few, the right vacant number 0.
num << n equals num*2^n (※※※)
>>: Right shift: After turning into binary, right shift several, left spare position number 0.
num >> n equals num/2^n (※※※)

6. Other operators:
expression 1-expression 2: expression 3:
expression 1 is an execution expression 2, otherwise an expression 3 is executed.
": Call the command line in the System DOS environment and execute it. However, because of security and cross-platform, we do not support the use of; eg: ' ipconfig '
@: Error Message control: Can temporarily mask to some small error message. But it is not advocated!

two mutable variables

In front of a variable name, add a $ symbol. You can use the value of the first variable as the name of the new variable.

$hello = "Hello1";
$ $hello = "World"; //$hello 1
$$ $hello = "jredu"; //$world

three address symbols


&: variable name plus & can take out the address of the variable in memory and assign it to another variable.
$num 2 = & $num 1; //Remove the NUM1 address to num2, which is equivalent to the reference data type we are referring to. The values of num2 and NUM1 will change at the same time.

four branching and looping

1. If the judging condition
For more details, please click on " Curiosity!" The second part of the previous chapter, "Basics of Getting Started with PHP," here, bloggers don't introduce ...

2, ElseIf
In PHP, ElseIf statements can be ligatures or separated by spaces;

For example:
else if () √
ElseIf () √

3. Switch
In PHP, the switch structure is judged using = = rather than = = =
In PHP, continue can be used with the switch structure, with the same effect as break.
In PHP, continue and break can be followed by numbers, which means skipping several layers of loops or switch;
Eg:break 3; Indicates terminating 3-layer loop

4. Do-while Cycle
Do-while the end of the loop must be added with a semicolon.
bo=

}while ();

5. Process Control Statements

1. Break: Terminates the loop of this layer; A number can be followed by a break, which means that several layers of loops are terminated. Break 3 to terminate the 3-layer loop.
2, continue: skip this cycle; Continue can also be followed by numbers, which means skipping several layers of loops
3, return: Terminates the current function, and returns the value (if any), but generally only used in the function, the script does not recommend the use of return;
4, exit (mixed concluding)/die (mixed concluding) function: Directly end the current PHP script!!
If a parameter is passed in, the closing is printed first, and then the current script is ended.

Five flow control statement Goto

1. Usage:

Define a jump anchor point, "identifier"--"JR:"
In any position, set the goto statement to jump to the specified anchor point: "Goto JR;"


2. Function:

Jumps directly to the set identifier location when a goto statement is encountered.


3, used to implement the branch.
Note: The goto statement simply jumps the current program control flow to the specified anchor point, but is not responsible for executing a few lines of code down.
That is, all the code down from the anchor point executes sequentially. If you implement a Multipath branch, you need to match the Goto statement to skip the other branches. (see case study below)


4. Goto Implementation Loop:

See the case. However, in Goto, jumping out of a loop cannot use break.


5. The advantages and disadvantages of goto statement:
① Advantages: The use of flexible and convenient, instruction-level statements, faster efficiency, better performance.
② Cons: The massive use of Goto is a disaster for the structuring of the code.
It is not conducive to a clear code structure, is not conducive to understanding the code, and it is very likely to skip some important declaration statements, resulting in code errors.

Theory is inferior to practice, see code below for details ↓↓↓

1 //Goto statement Implements branching2    /*$num = true;3 if (! $num) {4 Goto JH;5 }else{6 Goto Jr;7    }8    9 Jr:Ten echo "3333333333333<br/>"; One echo "4444444444444<br/>"; A Goto JJ; -     - JH: the echo "5555555555555<br/>"; - echo "6666666666666<br/>"; -     - JJ:*/ +     -    //[1]goto Cycle +    $num= 0; AJr at    Echo"1222222222221<br/>"; -    $num++; -    if($num<5){ -Goto JJ;//jump out of loops with Goto, note that break is not available -    } - Goto Jr; in     -Jj: to    Echo"Hahaha"; +     -    /*//[2]goto Implementing Loops the $num =0; * Jr: $ echo "11111<br>";Panax Notoginseng $num + +; - if ($num <5) { the Goto Jr; +     }*/

This is what we want to share with you today, I hope we have some help.

Bloggers once again remind you that theoretical knowledge is the basis of knocking good code, can not be ignored! "Basic PHP Basics" will continue to update, thank you for your attention ~ ~ ~


Sunset Hope
Source:http://www.cnblogs.com/hope666/

Getting Started with PHP Basics (ii)---prerequisites!

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.