Concepts related to operators learned in php

Source: Internet
Author: User
Tags bitwise operators
The following code describes the concepts related to operators learned by php:
/* Operator number (PHP) operator symbol
*
* By operator number:
* 1. arithmetic operators +-*/% + + --
* 2. string operators. Concatenation Operators
* 3. value assignment operator = + =-= * =/= % =. =
* 4. Comparison operators >======! = <>! =
* Comparison operator --- condition operator --- relational operator
* There is only one comparison result: boolean true false
* === The comparison requires the same content and type
*! = When compared, the content is not the same and the type is also required.
* 5. logical operators & and | or! Or not
* Logical operators can only operate bool-type values, and return bool-type values.
* 6. bitwise operators & | ^ ~ <>>>>
* 7. Other operators? : ''@ =>->::& $
* ''Is used to execute the operating system kernel.
* @ Used to block error messages
* We recommend that you use "()" to change the expression priority.
*
* % Has two purposes: Division operation; control range; do not use decimal places or negative numbers
* % Convert the numbers on both sides of the operator into integers and perform the remainder division.
*/
// Use the % symbol to determine the 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; first use a variable and then increase by 1
+ + $ A; // $ a = $ a + 1; first, auto-Increment 1.
$ A --; // $ a = $ A-1; use variables first, then subtract 1
-- $ A; // $ a = $ A-1; first auto minus 1, then variable
Echo $ a; // The result is 10.
// ++ -- Differences in 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;
// Use of the string operator.
$ Name = "tom ";
$ Age = 27;
$ Height = 1.75;
Echo "My name is: {$ name} my age is: {$ age} my height is: {$ height} meters
";
Echo 'My name is: '. $ name.' My age is: '. $ age.' My height is: '. $ height. 'MI '.'
';
Echo "\ $ age =". $ age; // $ age = 27
Echo "My name is: {$ name} my age is: {$ age} my height is: {$ height} meters
"; // Use of the value 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 $;
$ Str ='



';$ Str. =' ';$ Str. =' ';$ Str. =' ';$ Str. ='
';
$ Str. ='
';
Echo $ str; // output a table
// Comparison operator
Var_dump (15> 6); // return bool (true)
$ A = 15;
If (15 = $)
{
Echo "a = 15 ";
}
Else
{
Echo "! = 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 the user name and password
$ Username = "admin ";
$ Password = "123456 ";
$ Email = "290080604@qq.com ";
If ($ username = "admin" & $ password = "123456 ")
{
Echo "the user name and password are correct ";
}
If ($ username = "" | $ password = "" | $ email = "")
{
Echo "none of them can be blank ";
}
// Bitwise operator
$ A = 20; // 00010100
$ B = 30; // 00011110
/*
* 20 00010100
* 30 00011110 &
*-----------------------------------
* 00010100
*
*/
$ C = $ a & $ B;
Echo $ c;
/* Supplement, & | it can also be used for logical operations.
* & | Short circuit problem:
* & When performing an operation, if the first number is false, whether the latter is true or not, and the entire expression is false, the subsequent operands are not executed;
* | When performing an operation, if the preceding number is true, whether the following number is false and the entire expression is true, the subsequent operands are not executed;
* However, & or | during operation, both sides are executed.
*/
$ 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 single bit is composed of eight binary numbers (for example, 00000000 ),
A byte consists of eight digits, so there are 32 binary numbers.
Original Code: the highest bit represents a positive number with 0, and 1 represents a negative number.
+ 7 00000111
-7 10000111
Anticode: if a number is positive, its anticode is the same as the original code;
If a number is negative, the symbol bit is 1, and the rest of the code is reversed;
+ 7 00000111
-7 11111000
+ 0 00000000
-0 11111111
Complement: if a number is positive, its complement and reverse code are the same as the original code.
If a number is negative, its complement = anti-code + 1 removes the overflow bit of the highest bit
-7. original code 10000111: Reverse Code 11111000
+ 1
Makeup 11111001
If a negative complement is known, convert it to a decimal number.
1. get the opposite information for you first
2. convert it to a decimal number.
3. add a negative number and subtract 1.
Example: code 11111010
Decimal 00000101
4 + 1 = 5
-5-1 =-6
Bitwise operator:
& Bitwise and | bitwise OR ^ bitwise OR ~ Bitwise inversion
Example: bitwise and 01101101
& 00110111
00100101
Conclusion: only 1 is 1.
By bit or 01101101
| 00110111
01111111
Conclusion: only 0 0 is 0.
By bit or 01101101
^ 00110111
01011010
Conclusion: only 1 0 or 0 1 is 1. (It can also be understood that the status is 1 (true ))
Bitwise inversion ~ 00110111
11001000
Conclusion: change 0 to 1, 1, and 0.
Shift operator:
Shift Left: <shift right with a symbol:> unsigned shift right: >>>
Example: number x <2 x> 2 x> 2
17 00010001 01000100 00000100 00000100
-17 11101111 10111100 11111011 00111011
Conclusion: If positive numbers are left and right, 0 is added. if negative numbers are left, 0 is added. if positive numbers are left, 1 is shifted to the right, and 0 is not added.
*/
// Use other operators
$ A = 10;
$ B = $ a> 5? $ A: 5; // triplicate operator. if it is set to $ B = $ a, otherwise $ B = 5
Echo $ B;
// Use ''to execute the shell command of the operating system
$ Str = 'ipconfig/all ';
Echo'
'; 
echo $str;
echo '
';
?>

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.