Summary PHP operator classification and usage _ PHP Tutorial

Source: Internet
Author: User
Summarize the classification and usage of PHP operators. PHP operators are the most commonly used in our programs. I recently read a PHP book to introduce the use of PHP operators. I would like to share them with you here. 1: arithmetic operator: the PHP operator is the most commonly used in our programs. I recently read a PHP book to introduce the use of the PHP operator. let's share it with you.

1: arithmetic operator:
-:-$ A: returns the negative value of.
+: $ A + $ B addition: sum of $ a and $ B.
-: The difference between $ a-$ B subtraction $ a and $ B.
*: The product of $ a * $ B multiplication $ a and $ B.
/: $ A/$ B Division $ a divided by the operator of $ B.
%: $ A % $ B modulo $ a divided by the remainder of $ B.

Note: the division sign ("/") always returns a floating point number, even if the two operations are integers (or integers converted from strings) this is also the case where the modulo $ a % $ B is a negative value.

Example:

 
  1. <Html>
  2. <Head>
  3. <Title>Php constant definition -- a Tao's essay Title>
  4. Head>
  5. <Body>
  6. Php
  7. $A=3;
  8. $B=4;
  9. $C=5;
  10. $D=6;
  11. // $D=-$;
  12. $E= $ A + $ B;
  13. $F= $ D-$ c;
  14. $G= $ A * $ d;
  15. $H= $ D/$;
  16. Echo "{$ e}<Br>";
  17. Echo "{$ f}<Br>";
  18. Echo "{$ g}<Br>";
  19. Echo "{$ h}<Br>";
  20. ?>
  21. Body>
  22. Html>

2: Assignment operator:

The basic assignment operator is "= ". At first, you may think it is "equal", but it is not. It actually means assigning the value of the right expression to the number of left operations.

1): Simple assignment:

 
  1. &a="http://www.admin300.com"$b=2008
3): Note that the value assignment operation copies the value of the original variable to the new variable (passing the value assignment), so changing one does not affect the other. This is also suitable for copying values such as large values in a tight loop. PHP 4 supports reference assignment and uses the $ var = & $ othervar; syntax, but this is not possible in PHP 3. "Reference value assignment" means that both variables point to the same data without any data copy. PHP operator skills: the value of the value assignment expression is the value assigned. That is to say, the value of "$ a = 3" is 3. In this way, you can do some tips:

 
  1. $a = ($b = 4) + 5;

Bytes. 1: arithmetic operator :...

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.