Learning notes for PHP operators

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

operator symbol (action symbol)

The function of the operation symbol is divided into

One: Arithmetic operators (+-*/% + +-)
%//has two purposes: integer operation, control range operation (do not use decimal, and do not use negative numbers)
Turns the numbers on both sides to integers and then divides them.

Example:
Code:
$year =?;
if ($year%4==0 && $year%100!=0) | | $year%400==0) {
echo "is a leap year";
}else{
echo "is not a leap year";
}
Code:
$a = 109009;
echo $a% 10;

+ + and-

Example:
Code:
$a = 10;

$a + +; $a = $a +1 first with a variable in the self increase 1
+ + $a; $a = $a +1 First use the self-increase 1 and then use the variable
$a--; $a = $a-1 use variable and then subtract 1 from the first
--$a; $a = $a-1 first from minus 1 and then with variable
Code:
$a = 10;
$b = $a + +; b=10,a=11
$c =--$b; C=9,b=9
$d = $c + + + + + + + $c; d=20,c=11
$e = $d-----$d; E=2,d=18
Two: String operators (.)

Three: assignment operator (= = = = *=%=. =)

Example:
Code:
$a = 10;
$a +=10; $a = $a +10;
$a-=10; $a = $a-10;
$a *=10; $a = $a *10;
$a/=10; $a = $a/10;
$a%=10; $a = $a% 10;
$a. = "ABC"; $a = $a. " ABC ";
Four: Comparison operators (> < >= <= = = = =!= or <>!==)//Also called conditional operators, relational operators
After comparison there is only one result: Boolean true False

= = = = = = = = = = =/= =

Example:
Code:
$a = 10;
if ($a =100) {
echo "correct";
}else{
echo "Error";
//The result is correct, but 10 is not greater than 100 because = is an assignment, not a comparison symbol

Code:
$a = 100;
if ($a ==100) {
echo "correct";
}else{
echo "Error";
//The result is correct, because = = = meaning is equal to or not.

Code:
$a = 100;
if ($a = = "100") {
echo "correct";
}else{
echo "Error";
//result is correct, because = = compare content, do not require type

Code:
$a = 100;
if ($a = = "100") {
echo "correct";
}else{
echo "Error";
//The result is an error because = = = Not only compares content, but also requires type, "100" is a character type

Code:
$a = 100;
if ($a ===100) {
echo "correct";
}else{
echo "Error";
}//Results are correct

!==//This is the requirement that the content is not the same and the type is different

Five: Logical operators (&& OR and | | OR OR! or not)

Logical operators can only manipulate bool values, and return a bool type

  Example:
Code:
   Var_dump (True && true); //true
   var_dump (True & & false); //false
   var_dump (true | | false); //true
   var_dump (!true); nbsp False
   Var_dump (!false); //true
 
  SIX: Bitwise operators (& | ^ ~ << >> >> ;>)
 & | can be used as both a logical operation symbol and a bitwise operational symbol
  short-circuit problem:&& and | | A short-circuit
 && when doing an operation, If the previous argument is false, then it is true, and the entire expression is false, so the following operand is not executed
 | | If the previous argument is true if the preceding parameter is false, the entire expression is true. So I'm not going to do the following operand
 & or | When doing an operation, both sides will be executed
  seven: Other operators (?: "@ =>->:: & $)
 
condition? Set up execution Here: Do not set up the execution here

  Example:
   code:
  $a =10
  $b = $a >5? $a:5; //If $a is greater than 5, assign $a to $b, or you will assign a value of 5 to $b< br>  echo $b; //result is a
 
  '//Execute system command
  Example: Www.111cn.net
  Code:
$ip = ' IP Config ';
echo "<pre>";
Echo $ip;
echo "</pre>";
  @ //Masking error
 
Example:
  code:
  @getType ();
 echo "Mkmkmkmkmkmk<br> ;";

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.