PHP 0,null,empty, NULL, FALSE, string relationships in detail _php tutorial

Source: Internet
Author: User
In a project encountered a strange problem, it cost me a lot of time is not resolved, the final debugging found is the question of judgment-about 0 and "(empty single quotation marks, for good see I added a space), I found 0==" incredibly set up, depressed at the same time decided to write a simple page test, vowed to 0,null , empty, NULL, false the relationship is clear. Because this is likely to be a bug in some key places where we write programs that have Web sites. In particular, may affect the landing and other special places of security and logic correctness, although this is a very basic knowledge point, but many people, including some experts may be 0,null,empty, empty, false relationship is very vague. So it is still very necessary to do a test by yourself.
PHP Program code:
Copy CodeThe code is as follows:
//========= determines the relationship between 0 and ' and empty null false start =========//
if (' safdasefasefasf ' ==0) {
echo "The string is converted to a number equal to 0
";
}//output: The string is converted to a number equal to zero.
This is one of the key examples
This is explained in the manual: This value is determined by the first part of the string. If the string starts with a valid numeric data, the number is used as its value, otherwise its value is 0 (0).
Which means ' 3asfdf ' ==3; ' Adsfasdf ' ==0 quite to notice
$a = 0;
if ($a = = ") {
echo "0 equals"
";
}//output:0 Equals ' '
if (trim ($a) = = ") {
echo "Trim (0) equals"
";
}//no Output

if ($a = = =) {
echo "0==="
";
}//no Output
if (empty ($a)) {
echo "is empty
";
}//output: ' Is empty
if (Is_null ($a)) {
echo "0 is null
";
}//no Output
if (Is_numeric ($a)) {
echo "0 is numeric
";
}//output:0 is numeric
if (is_string ($a)) {
echo "0 is string
";
}//no Output
if (strval ($a) = = ") {
echo "0 is" converted into a string
";
}//no Output
========= determines the relationship of 0 and ' and empty null false end =========//
========= judgment ' and 0 and empty null false relationship start =========//
$b = ";
if ($b ==0) {
echo "'" Equals 0
";
}//output: ' Equals 0
if (! ') {
echo "' is false.
";
}//output: "is false
if (!0) {
echo "0 is false.
";
}//output:0 is False
========= judgment ' and 0 and empty null false relationship end =========//
echo "In judging the Empty (") must be careful, 0 is equivalent to ", 0 and" are equivalent to null characters and false, the best to judge the empty = = = ";
?>

The result of the output is: 0 equals "" is the empty 0 is numeric "equals 0" or false 0 is false in judging the empty (") must be careful, 0 is equivalent to", 0 and "are equivalent to null characters and false, the best to determine the empty = = = Only this explanation: 0 is also equivalent to ", 0 and" are equivalent to null characters and False
When judging the empty (") must be careful, 0 is equivalent to", 0 and "are equivalent to null characters and false, the best to judge the empty = = =;

http://www.bkjia.com/PHPjc/327751.html www.bkjia.com true http://www.bkjia.com/PHPjc/327751.html techarticle in a project encountered a strange problem, it took me a lot of time is not resolved, the final debugging found to be the question of judgment-about 0 and "(empty single quotes, for good see I plus ... )

  • 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.