In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use php logic operator". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use php logic operator" can help you solve the problem.
In php, logic operators are symbols for logic operations, which can be used to combine the results of logic operations and are a group of very important operators in programming. There are six kinds of logic operators: "and" and "& &" for logic and, "|" and "or" for logic OR, "xor" for logic XOR, "!" Indicates that the logic is not.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, a logical operator is a symbol for performing logical operations.
Logical operators, which are used to combine the results of logical operations, are a group of very important operators in programming.
The logical operators in PHP are shown in the following table:
Logical operator example when the result is true & & or and (logical and) $m & & $n or $m and $n when both $m and $n are true, and either of $m and $n is false | | or or (logical OR) $m | | $n or $m or $n as long as either of $m and $n is true, the result is true xor (logical XOR) $m xor $n when $m and $n are true and the result is true! (logical not)! $m when $m is false The result is true.
The relationship between "&" or "and" logic and
When the left and right conditions are TRUE at the same time, the result is FALSE if either of the two conditions of TRUE; is FALSE. When the condition on the left is FALSE, it will skip the condition on the right and return to FALSE directly.
[example] assume that the conditions for conscription are met between the ages of 18 and 25, and Xiaoming is 21 years old to judge whether Xiaoming is suitable to serve as a soldier. The implementation code is as follows:
The if else statement we use in the example will be explained in more detail later.
The running results are as follows:
Meet the requirements of being a soldier!
"| |" or "or" logic or
If one of the two conditions is TRUE, the result is TRUE;. If both conditions are FALSE, the result is FALSE. When the left condition is TRUE, the judgment of the right condition will be skipped and TRUE will be returned directly.
[example] adjust the above example and implement it using logic or operator. The code is as follows:
"!" Logic is not
Invert a Boolean value. For example:! true = false,! false = true,! 10 = false.
[example] also use the previous example, using logical non-operator implementation, the code is as follows:
[example] determine whether the specified year is a leap year:
The running results are as follows:
2020 is a leap year! This is the end of the introduction to "how to use php logical operators". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.