PHP Learning Operators related concepts

Source: Internet
Author: User
Tags bitwise operators
The code is as follows:
<?php
/* OP symbol (PHP) Action symbol
*
* According to the function of the operation symbol is divided into:
* One, arithmetic operator +-*/% + +--
* Two, string operators. Join operators
* Third, assignment operator = + = = *=/=%=. =
* Iv. comparison operators > < >= <= = = = = = = = <>!==
* Comparison operators---Conditional operators---relational operators
* Only one of the results after comparison: Boolean true False
* = = = does not only require the same content, but also requires the same type
*!== different content when comparing, also require different type
* Five, logical operators && OR and | | OR OR! or not
* Logical operators can only manipulate values of type bool and return a value of type bool
* Six, bit operators & | ^ ~ << >> >>>
* Seven, other operators? : ' @ + =:: & $
* ' to execute operating system kernel '
* @ To block out error messages
* It is recommended to use "()" to change the priority level of an expression
*
*% has two purposes: divide operation, control range, do not use decimals, and do not use negative numbers
*% will be the number of the operators on both sides to integer after the remainder.
*/
Use% symbol to judge leap year
$year = 2011;
if ($year%4==0 &&%year%100!=0) | | $year%400=0)
{
echo "Run Nian";
}
Else
{
echo "not run Nian";
}
+ +--Use of symbols
$a = 10;
$a + +; $a = $a +1; Use variables first, then increment by 1
+ + $a; $a = $a +1; Increment by 1 First, in the variable
$a--; $a = $a-1; Use the variable first, and then subtract 1 from it.
-$a; $a = $a-1; Subtract 1 First, then use the variable
echo $a; Result is 10
+ +--the difference between operations
$a = 10;
$b = $a ++;//b=10,a=11
$c =--$b;//c=9,b=9
$d = $c + + + + $c; d=20,c=11
$e = $d-----$d; d=18,e=2
Echo $d;
The string operator. The use
$name = "Tom";
$age = 27;
$height = 1.75;
echo "My name is: {$name} My age is: {$age} My height is: {$height} m <br>";
Echo ' My name is: '. $name. ' My age is: '. $age. ' My height is: '. $height ' m '. ' <br> ';
echo "\ $age =". $age; $age =27
echo "My name is: {$name} My age is: {$age} My height is: {$height} m <br>";//use of the assignment operator
$a = 10;
$a +=10; $a = $a +10;
$a-=10; $a = $a-10;
$a *=10; //...
$a/=10; //...
$a%=10; $a = $a% 10;
$a. = "ABC";//$a = $a. " ABC ";
echo $a;
$str = ' <table> ';
$str. = ' <tr> ';
$str. = ' <td> ';
$str. = ' </td> ';
$str. = ' </tr> ';
$str. = ' </table> ';
echo $str;//Output a table
Comparison operators
Var_dump (15>6);//returns BOOL (TRUE)
$a = 15;
if (15== $a)
{
echo "A=15";
}
Else
{
echo "A!=15";
}
Use of logical operators
Var_dump (True && true);//true
Var_dump (True && false);//false
Var_dump (True | | false);//true
Var_dump (!true);//false
Var_dump (!false);//true
Determine User name password
$username = "admin";
$password = "123456";
$email = "290080604@qq.com";
if ($username = = "Admin" && $password = "123456")
{
echo "User name password is correct";
}
if ($username = = "" | | $password = = "" | | $email = = "")
{
echo "One cannot be empty";
}
Bitwise operators
$a = 20; 00010100
$b = 30; 00011110
/*
* 20 00010100
* 00011110 &
*-----------------------------------
* 00010100
*
*/
$c = $a & $b;
Echo $c;
/* Supplemental,& | It can also be used as a logical operation
* && | | Short-circuit problem:
* && at the time of operation, if the previous number is false, then whether the following is true, the entire expression is false, so do not go to the subsequent operand;
* || In the case of an operation, if the preceding number is true, then whether the subsequent number is false and the entire expression is true, the subsequent operand is not executed;
* However,& or | Both sides will be executed when the operation is performed.
*/
$a = 10;
if ($a >5 | | $a ++<100) {}
echo $a;//Output 10
$b = 10;
if ($b >5 | $b ++<100) {}
echo $b;//Output 11
/*
Bit concept: A bit is made up of 8 binary numbers (Example 00000000),
A byte consists of 8 bits, then there are 32 binary numbers.
Original code: Highest bit with 0 for positive, 1 for negative
+7 00000111
-7 10000111
Anti-code: If a number is positive, then its inverse code and the same as the original code;
If a number is negative, then the sign bit is 1, the rest of you are the original code to take the reverse;
+7 00000111
-7 11111000
+0 00000000
-0 11111111
Complement: If a number is positive, then its complement and inverse code are the same as the original code
A number if negative, then its complement = anti-code +1, remove the highest bit overflow bit
-7 Original Code 10000111 anti-code 11111000
+1
Complement 11111001
The complement of a negative number is known, and it is converted to decimal.
1. First, you take the counter
2. Convert it to a decimal number
3. Add minus, minus 1.
Example: Complement 11111010
Take the reverse 00000101
4+1=5
-5-1=-6
Bitwise operators:
& Bitwise vs. bitwise OR ^ bitwise XOR or ~ bitwise inverse
Example: Bitwise AND 01101101
&00110111
00100101
Conclusion: Only 1 1 is 1.
Bitwise OR 01101101
|00110111
01111111
Conclusion: only 0 0 is 0.
Bitwise XOR or 01101101
^00110111
01011010
Conclusion: only 1 0 or 0 1 o'clock is 1. (can also be understood as being in a different state of 1 (true))
Bitwise REVERSE ~00110111
11001000
Conclusion: Change 0 to 0
Shift operators:
Move left:<< sign right:>> unsigned right shift:>>>
Example: Number x x<<2 x>>2 x>>>2
17 00010001 01000100) 00000100 00000100
-17 11101111 10111100 11111011 00111011
Conclusion: Positive movement is 0, negative left 0, with symbol right shift 1, without symbol complement 0
*/
The use of other operators
$a = 10;
$b = $a >5? $a: 5;//ternary operator If $b= is established $a otherwise $b=5
Echo $b;
Use "to execute operating system shell commands
$str = ' Ipconfig/all ';
Echo ' <pre> ';
Echo $str;
Echo ' </pre> ';
?>
  • 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.