PHP Course NOTE 2

Source: Internet
Author: User
Tags bitwise operators http post php example php operator

Lessons from PHP self-plus (+ +) self-subtraction (-) operations need to be noted

1. $a = false;

$b = true;

echo $a; Result is 1

Echo $b; Result is empty

Boolean type

2. $c = true;

$c + +;

Echo $c; Result is 2

Var_dump ($c); The result is still bool true

3. $c = false;

$c + +;

Echo $c; Result is empty

Var_dump ($c); The result is still bool false

4. $d = "a";

$d = $d +1;

Echo $d; The result is 1 because the string is 0

Var_dump ($d); The result is an int

5. $d = "a";

$d + +;

Echo $d; The result is B

Var_dump ($d); Result is a string

6. $d = "Z";

$d + +;

Echo $d; The result is a AA, which turns into two letters and continues to be added.

Var_dump ($d); Result is a string

7.++ If the addition operation is the same as the x+1.

However, if the Boolean and string types are not.

class php assignment operator

1. $a + = 1; $a = $a + 1;

2. $str = "Pull Wind";

$str 1 = "juvenile";

echo $str. = $str 1; Output: Shavers teenager

Class hours php comparison operator

1. The result of the comparison is a Boolean value, which is usually used in the IF and while statements.

2. Floating-point type is approximate number, try not to use equal ratio, some languages can wait, some languages can not.

Class php logical operators

Class hours php logical operator characteristics (short circuit)

1. Features: Short circuit

&& the first judgment is false, the result is false, the back does not need to judge

|| The first judgment is true, the result is true, and the back does not need to be judged

2.

$a = 0;

$b = 0;

if ($a = 3 && $b = 3) {

$a + +;

$b + +;

}

echo $a. ",". $b;

The operation level of the assignment operator is the lowest

3&& first get to the left is true, then $b = 3 to the right is true. So the result is true and assigned to a. The final result is a=1,b=4.

3.

$a = 0;

$b = 0;

if ($a = 3 | | $b = 3) {

$a + +;

$b + +;

}

echo $a. ",". $b;

Where Direct 3 | | To get the result to be true, assign a value to a

The final result is a of 1, because true, B is from 0 to 1

Class The bitwise operators in PHP exist in memory form

bit operators in PHP and &

1.var_dump (True & false); The result is int 0

Var_dump (True + false); The result is int 1

2.var_dump ("A" & "a"); The result is a, because A is 65,a is 97

3. Bit operation does not short circuit

Class of PHP bitwise operators or other bitwise operators

1. & | Most are also used to make judgments, but the use of it is not short-circuit reasons.

2.<< the left shift once and multiply it by 2.

>> shift Right one time is equivalent to dividing by 2

Class hours php other operators

1. Operational elements? Operational elements: operational elements

Conditions? Expression 1: Expression 2

If the condition is true, the expression 1 is executed, and the expression 2 is not established.

Class hours the precedence and expression of the PHP operator

1. The expression is a sentence with variables or constants and symbols involved. Simple is the assignment statement, complex is the function.

PHP Process Control Overview

1. Sequential structure

2. Branching structure

3. Cyclic structure

Class of PHP branch structure

1. Single conditional branching structure (IF)

2. Bidirectional conditional branching structure (ELSE clause)

3. Multi-directional conditional branching structure (elseif sentence, switch statement)

4. Tidal Loading Conditions Branch structure

Classes PHP single conditional branching structure and bidirectional conditional branching structure

1. if (bool) {

More than

}

2.if (bool) single; But it's better to add {}

Class hours PHP Multi-directional conditional branching structure (ElseIf clause)

1.

$score = 90;

if ($score > && $score <=100)
{
echo "Fuxk A";
} else if ($score > && $score <= 90) {
echo "Good B";

}

2. In the If Else statement, the multiple branches can only go in one.

Class of PHP Multi-directional Conditional branch (switch statement) 1

1. Switch () must be a variable in parentheses

Switch (variable) {

Case value 1:

Statement 1;

Statement N;

Break

Case Value 2:

Statement 2;

Break

Case Value 3:

Statement 3;

Break

...

}

2. In switch, put multiple case statements, case spaces, followed by a value, followed by a colon:

3. You can use default when no match is used.

Lesson PHP Multi-directional Conditional branch (switch statement) 2

1. If there are too many statements in the case, you need to make multiple statements into a function. Make a simple call.

The type of the 2.switch (variable) variable. Only two types are allowed, integer and string.

A 3.case match can match more than one. Put a break at the bottom of the last one

For example Case 1:

Case 2:

Case 3:

echo "PHP";

Break

4. The statement written by switch can be written, else if all can be written. Conversely, it is not.

5. It is most convenient to use siwtch when matching with a single value.

The 6.else if is used best when judging the range.

Class of php nest-like branching structure

1. Nesting levels try not to exceed 3 layers

PHP Example (simple calculator) 1

1.url get is a value that is passed by URL parameter, but has a size limit

Cons: Easy to get to

2.http Post

3. $_get is an array.

4.$_post is also an array.

Lesson PHP Example (Simple calculator) 2

PHP instance (simple Calculator) 3

PHP Example (Simple Calculator) 4

<?php
Error_reporting (E_all & ~e_notice);

if (Isset ($_post[' Sub ')) {
echo "User is submitted";

$bz = true;

$errormess = "Have the above problems:<br>";

if ($_post[' num1 ' = = "") {
$bz = false;
$errormess. = "The first number cannot be empty <br>";

} else {
if (!is_numeric ($_post[' NUM1 ')) {
$bz = false;
$errormess. = "The first is not a number cannot be calculated <br>";
}
}

if ($_post[' num2 ' = = "") {
$bz = false;
$errormess. = "The second number cannot be empty <br>";
}else {
if (!is_numeric ($_post[' num2 ')) {
$bz = false;
$errormess. = "The second is not a number cannot be calculated <br>";
}

}

if ($BZ) {

This is the result of the calculation.
$sum = "";

Determine what the user chooses is the operation symbol
Switch ($_post[' YSF ')} {
Case ' + ':
$sum = $_post[' num1 ') + $_post[' num2 '];
Break
Case '-':
$sum = $_post[' num1 ')-$_post[' num2 '];
Break
Case ' x ':
$sum = $_post[' num1 ') * $_post[' num2 '];
Break
Case '/':
$sum = $_post[' num1 ')/$_post[' num2 '];
Break
Case '% ':
$sum = $_post[' num1 ']% $_post[' num2 '];
Break

}
}

}

Echo ' <br> ';
?>

<title> Simple Calculator </title>

<body>
<table border= "0" width= "align=" Center >
<form action= "jsq.php" method= "POST" >
<caption>

<tr>
<td>
<input type= "Text" size= "5" name= "NUM1" value= "<?php echo $_post[' num1 ']?>"/> <br>
</td>

<td>
<select name= "YSF" >
<option <?php if ($_post[' YSF ']== "+") echo "selected"?> value= "+" > + </option>
<option <?php if ($_post[' YSF ']== "-") echo "selected"?> value= "-" >-</option>
<option <?php echo $_post[' ysf ']== "x"? "Selected": "?> value=" x "> x </option>
<option <?php if ($_post[' YSF ']== "/") echo "selected"?> value= "/" >/</option>
<option <?php if ($_post[' ysf ']== "%") echo "selected"?> value= "%" >% </option>
</select>
</td>

<td>

<input type= "Text" size= "5" name= "num2" value= "<?php echo $_post[' num2 ']?>"/> <br>
</td>
<td>
<input type= "Submit" Name= "sub" value= "Calculation" >
</td>
<tr>

<tr>
<TD colspan= "4" >

<?php
if ($BZ) {

echo "calculation result: {$_post[' Num1 '} {$_post[' YSF '}} {$_post[' num2 ']} = {$sum}";
} else {

Echo $errormess;
}

?>
</td>
</tr>
</form>
</table>
</body>

Introduction to PHP cycle structure in class

Class in PHP loop structure while statement

1. The cycle must have an exit condition

2. Counting loops suitable for use for to write

3. Conditional loops are suitable for use while to write

4. The while loop is the majority in PHP

Application of PHP loop structure while in class

1. Nesting loops

Class PHP loop structure do-while statement

1. Do and must be executed first. But the while is not allowed to be executed as long as it is judged.

Class a PHP loop structure for statement

1.for (expression 1; expression 2; expression 3) {

}

Expression 1 is given an initial value and executed only once

Expression 2 is used as a loop condition, conditional expression.

Expression 3 is executed at the end of the loop, and the self-increment condition

PHP Course NOTE 2

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.