PHP empty string describes the relationship between 0, null, empty, and false

Source: Internet
Author: User
: This article mainly introduces the relationship between 0, null, empty, and false in PHP empty strings. For more information about PHP tutorials, see. // Determine the relationship between 0 and '', null, empty, and false
$ A = 0;
Echo "relationship between 0 and'', empty, null, and false :";
If ($ a = ''){
Echo "0 = '';";
} Else {
Echo "0! = '';";
}
If (trim ($ a) = ''){
Echo "trim (0) = '';";
} Else {
Echo "trim (0 )! = '';";
}
If (strval ($ a) = ''){
Echo "strval (0) = '';";
} Else {
Echo "strval (0 )! = '';";
}
If ($ a = ''){
Echo "0 = '';";
} Else {
Echo "0! = '';";
}
If (empty ($ )){
Echo "0 is empty ;";
} Else {
Echo "0 is not empty ;";
}
If (is_null ($ )){
Echo "0 is null ;";
} Else {
Echo "0 is not null ;";
}
If (is_numeric ($ )){
Echo "0 is numeric ;";
} Else {
Echo "0 is not numeric ;";
}
If (is_string ($ )){
Echo "0 is string ;";
} Else {
Echo "0 is not string ;";
}
If (! $ ){
Echo "0 is false ;";
} Else {
Echo "0 is not false ;";
}
// Judge the relationship between ''and 0, null, empty, and false.
$ A = '';
Echo "the relationship between'' and 0, empty, null, and false :";
If ($ a = 0 ){
Echo "'' = 0 ;";
} Else {
Echo "''! = 0 ;";
}
If (intval ($ a) = 0 ){
Echo "intval ('') = 0 ;";
} Else {
Echo "intval ('')! = 0 ;";
}
If (empty ($ )){
Echo "'' is empty ;";
} Else {
Echo "'' is not empty ;";
}
If (is_null ($ )){
Echo "'' is null ;";
} Else {
Echo "'' is not null ;";
}
If (is_numeric ($ )){
Echo "'' is numeric ;";
} Else {
Echo "'' is not numeric ;";
}
If (is_string ($ )){
Echo "'' is string ;";
} Else {
Echo "'' is not string ;";
}
If (! $ ){
Echo "'' is false ;";
} Else {
Echo "'' is not false ;";
}
// Determine the relationship between null and '', 0, empty, and false
$ A = null;
Echo "relationship between null and'', 0, empty, and false :";
If ($ a = ''){
Echo "null = '';";
} Else {
Echo "null! = '';";
}
If ($ a = 0 ){
Echo "null = 0 ;";
} Else {
Echo "null! = 0 ;";
}
If ($ a = ''){
Echo "null = '';";
} Else {
Echo "null! = '';";
}
If ($ a = 0 ){
Echo "null = 0 ;";
} Else {
Echo "null! = 0 ;";
}
If (strval ($ a) = ''){
Echo "strval (null) = '';";
} Else {
Echo "strval (null )! = '';";
}
If (intval ($ a) = 0 ){
Echo "intval (null) = 0 ;";
} Else {
Echo "intval (null )! = 0 ;";
}
If (empty ($ )){
Echo "null is empty ;";
} Else {
Echo "null is not empty ;";
}
If (is_numeric ($ )){
Echo "null is numeric ;";
} Else {
Echo "null is not numeric ;";
}
If (is_string ($ )){
Echo "null is string ;";
} Else {
Echo "null is not string ;";
}
If (! $ ){
Echo "null is false ;";
} Else {
Echo "null is not false ;";
}
Echo "";


The output result is:

Based on the output results, I want to clearly understand the approximate relationship between null strings, 0, null, empty, and false, and flexibly use the methods in the above code during development, with good logic, there should be no problems.

The above introduces the relationship between 0, null, empty, and false in PHP hollow strings, including some content, and hope to help those who are interested in PHP tutorials.

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.