PHP Brothers Learn 30-60

Source: Internet
Author: User
Tags bitwise bitwise operators logical operators

Integral type
Floating point Type
Maximum length of integral type
A 32-bit representation of a binary number
Integers are saved by a 32-bit binary
There's no sign in the data.

Hello World
H e l l o
a->97
B->98
c->99
D 100
E 101
F 102
G 103
H->104

echo Ord (' H ');

H is a 1041 integer, which is stored by a 32-bit binary

00000000 00000000 00000000 00000000
High power frequency low power frequency

64 + 32 + 8

00000000 00000000 00000000 01101000

104

H

Altogether 31 bits storage bit one sign bit 1 negative 0 integer
The first is that the maximum symbol position is 2 of the 31-square
-2147483648~2147483648

$a = 10;
$b = 077; Octal
$c = 0xFF; Hexadecimal

More than an integer is floating point.

-------------------------------
Floating point number
Single precision + double precision
One and two digits after the decimal point
4 bytes

3e17 3*10 17-Time Square
3e-3 0.003
3E3 3000

Floating-point numbers do not make equal judgments
<script>
var a = 0;
for (Var i=0;i<10;i++) {
a+=0.1;
}
alert (a); 0.99999999
</script>
$a = Floor ((0.1+0.7) *10);---7

(0.1+0.7) *10-"7.9
Floating point saying calculation is inaccurate


Never believe that the floating-point numbers are accurate to the last one.
Never mind. Compare two floating-point numbers for equality (can be converted to integers to be exact)

-------------------------------
String type
Single or double quotation marks to indicate
PHP does not divide one or more characters, single and double quotes can be

Escape characters can be used in single and double quotes to make meaningful characters meaningless

In PHP similar to the characters in JS, no separate characters and strings.

The difference between single and double quotes in PHP.

The variables in JS need to be connected with the + sign
You can parse a variable in double quotes, but not in single quotes.
$int = 10;
$a = ' This is $int a '; This is $int a
$a = "This is $int a"; This is ten a
Separate () spaces with special characters
\ n
\ r
\ t
\$
\\
\"
Escape characters can be used in double quotes, which cannot be used in single quotation marks (only escape character escapes single quotes ' This is \ ' a\ ' in single quotes, and escape characters themselves can also be escaped)

function simple efficiency high energy use single quotation marks for single quotes
Use single quotes as much as you can


Main differences:
Variables can be used in double quotes
Escape characters can be used in double quotation marks, but only in single quotes with limited


-------------------------------
Using delimiters
1. Use <<< less sign
2. At the beginning of the delimiter (custom string) must be left next to the <<<
The end of the mark must be shelf write even spaces can not have a semicolon direct carriage
3. Use single quotation marks in the start bounding symbol. This turns the function that supports double quotation marks into single quotation marks. php5.3 new Features

-------------------------------
Data types in 8
Integral type
Floating point Type
Boolean
Character type
Array
Object
Resources
Null
Pseudo-type: is not a true type to illustrate the type of function @param number $a integral float @param mixed any type @param callback function as a parameter
-------------------------------
Conversion and detection between PHP data types
1. Casting
Var_dump ();
GetType ();---Gets the name string of the variable
$arr = 1;
echo GetType ($arr);

A.settype (variable, type);
$arr = 10;
SetType ($arr, "string");
echo GetType ($arr);

B. Precede the variable with the type symbol!! Good.
$a = "100";
$arr = (double) $a;

C.intval (); Floatval (); Strval ();
(int)
(Boolean)
(float)
(string)
(array)
(object)
Resource cannot be converted

2. Automatic conversion
function of type test
Strongly typed languages do not have to judge the type. The type of judgment is required in weakly typed languages.
Judging type
Is_bool ()
Is_array ()
Is_string ()
Is_int ()
Is_float ()
Is_object ()
Is_resource ()
Is_null ()
Is_scalar ()
Is_callable ()
Empty () content is blank
Whether the Is_null () type is empty

-------------------------------
Declaration and use of constants
Constant: Once declared, the value of this constant will not change
$a = 10;
is stored in the stack memory.
Memory is stored in 4 places.
Constants are stored in the initialization static segment.

Constants Use function declarations
1.define () Declares the
2. If the constant is not declared, the use of the constant name is automatically converted to a String 8 times times less efficient
3. Do not add the $ symbol in front of the constant name
4. Constant names are case-sensitive all uppercase
5. You can use the define third parameter to make the constant name case-sensitive, the default is False
6. The value of the constant only supports scalar data type 4 types integer floating-point String Boolean value
7. Cannot use Unset () to clear a constant
8. Use defined to determine if a constant exists
9. The range of constants is global. can be accessed anywhere
ECHO constant () read the value of the constant
Get_defined_constants (); Read all the Constants list

Pre-defined constants
Some of the predefined constants of PHP
PHP has many constants in each expansion pack
-------------------------------
Operation symbols
Unary operator!
Binary operators +-*/> < =
Ternary operator? :

Arithmetic operation symbol +-*/% + +--
Assignment operation symbol = + = =/=%=
Comparison operation symbols > < = = >= <=! =!==
Logical operation Symbols && | | !
Bit arithmetic Symbols & | ^ >> << ~
Other operational symbols? : @-

/denominator cannot be 0
+ No connection string function
Converting to integer and then modulo

+ + operation
$a = true;
$a + +; True
Do not participate in operations
The string's + + is ascending
A B c D


Assignment operators
=
+=
-=
*=
/=
%=
.=

Comparison operators
1. The result is a Boolean with the IF while and other statements
Congruent = = = Weak type has this. Value equality meta type equality
!==

<>! =

logical operators
&&
or | |
Not!
XOR must have only one for the real is true

Die-finding

logical operators
Shortest short-circuit phenomenon

Die ("Output and Exit program");

Assignment operator Stone the lowest
The Boolean value does not participate in the + + operation
$a = 0;
$b = 0;
if ($a =3 && $b =3) {
$a + +;
$b + +;
}
Echo ($a. " -". $b);

Bitwise operators
High efficiency
Bitwise operations
104 consists of 32-bit 0 and 12-binary
0 0000000 00000000) 00000000 00000000


& | ^ ~ << >>
& Two is 1 is 1 & 12
& it can also be a logical judgment, but not short circuit and && not the same
| No short-circuit phenomenon
^ xor or only two different is 1
~ Bitwise Inverse Single Count
Move left
Move right
12<<2
12>>2/2

Other operators
? :
"Inside the anti-quote is the OS command exec () system ()-ifconfig Linux IP
@ Mask Temporary error message echo @ $a; @gettype1 ();


Expressions: Variables and operators involved are expressions
Priority is resolved with parentheses

Process Control
1. Sequential structure
2. Branching structure if Else elseif switch
3. Cyclic structure

Nest-like branching syntax
<?php
if (Isset ($_post["sub"])) {
$bool = true;
$message = "Have the above problems:<br/>";
if (Empty ($_post["NUM1"])) {
$bool = false;
$message. = "The first value cannot be empty";
}else{
if (Empty ($_post["num2"])) {
$bool = false;
$message. = "The second value cannot be null";
}
}

if (!is_numeric ($_post["NUM1")) {
$bool = false;
$message. = "The first value is not a number cannot be calculated";
}else{
if (!is_numeric ($_post["NUM1")) {
$bool = false;
$message. = "The second value is not a number cannot be calculated";
}
}
$num 1 = $_post["NUM1"];
$num 2 = $_post["num2"];
$sum = "";
Switch ($_post[' YSF ')} {
Case ' + ':
$sum = $num 1 + $num 2;
Break
Case '-':
$sum = $num 1-$num 2;
Break
Case ' * ':
$sum = $num 1 * $num 2;
Break
Case '/':
$sum = $num 1/$num 2;
Break
Case '% ':
$sum = $num 1 $num 2;
Break
}
}
?>

<title></title>
<meta charset= "Utf-8" >
<body>
<form action= "index.php" method= "POST" >
<table border= "0" width= "align=" Center >
<caption><tr>
<td>
<input type= "Text" size= "5" name= "NUM1" value= "<?php echo $_post[" NUM1 "]?>" >
</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 if ($_post["YSF"]== "*") echo "selected";?> value= "*" >*</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 "]?>" ></td>
<td>
<input type= "Submit" Name= "sub" value= "Calculation"/>
</td>
</tr>
<tr>
&LT;TD colspan= "4" >
<?php
if ($bool) {
echo "calculation result: {$_post[' num1 ']}{$_post[' ysf ']}{$_post[' num2 ']}= $sum";
}else{
Echo $message;
}
?>
</td>
</tr>
</table>
</form>
</body>

Loop structure
While break;
Do{}while ();
For
Break
Continue
The exit;-program is here to end die ();

Goto
Echo 11111;
Goto NZ;
Echo 22222;
Echo 3333;
nz
Echo 4444;
Echo 55555;

PHP Brothers Learn 30-60

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.