Php increment/decrease operator

Source: Internet
Author: User

Php Tutorial increment/decrease operator


Only one operation of variables

The increment/decrease operator does not affect Boolean values. Decreasing the NULL value does not work, but the result of increasing the NULL value is 1.

 
Example name effect
+ + $ A add the value of $ a plus one, and then return $.
$ A ++ returns $ a after adding, and then adds the value of $.
-- Minus $ a before $ a minus one, and then returns $.
$ A -- returns $ a after subtraction, and then drops the value of $ a by one.

<? Php

$ A = 1;
Echo "add before"; // add one to the value of $ a, and then return $
Echo ++ $ a; // Display value 2

$ A = 1;
Echo "add after"; // return $ a, and then add the value of $
Echo $ a ++; // The displayed value is 1.

$ A = 2;
Echo "minus"; // subtract one from $ a, and then return $
Echo -- $ a; // The displayed value is 1.

$ A = 2;
Echo "minus"; // $ Returns $ a, and then drops the value of $ a by one.
Echo $ a --; // Display value 2
?>


<? Php
Echo "$ A = 5;
Echo "shocould be 5:". $ a ++. "<br/> n ";
Echo "shocould be 6:". $ a. "<br/> n ";

Echo "$ A = 5;
Echo "shocould be 6:". ++ $ a. "<br/> n ";
Echo "shocould be 6:". $ a. "<br/> n ";

Echo "$ A = 5;
Echo "shocould be 5:". $ a --. "<br/> n ";
Echo "shocould be 4:". $ a. "<br/> n ";

Echo "$ A = 5;
Echo "shocould be 4:". -- $ a. "<br/> n ";
Echo "shocould be 4:". $ a. "<br/> n ";
?>

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.