PHP Technical –php exclamation mark!!! Usage of (ternary operation)

Source: Internet
Author: User

---restore content starts---

if (Article = = useful) {Mad dot me;}

In PHP hold or other languages we often see the use of exclamation marks, a certain program language based friends know that the role of a single exclamation point is to take the opposite, that is, to take the negative side of the current results, such as:

<? PHP $a=true; Var_dump (! $a );? >

$a turns out to be true after a $ A is turned false, this usage is often seen in programs, but the use of double exclamation points may be much less. In fact, double exclamation point is equivalent to the ternary operation in the programming language ($a? $b: $c), such as

<? PHP $a=true; if (!! $a {  echo ' OK ';} Else {  echo ' error ';}? >

!! $a return a Boolean value (True or false), some friends may ask why this is used, directly in the normal way to do different? In fact, but as a programmer must be a broad understanding of the various writing procedures, not to be written by others can not understand the program. hehe, personal view!

PHP Technical –php exclamation mark!!! Usage of (ternary operation)

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.