PHP hollow string introduces the relationship between 0, null, empty and false_PHP tutorial

WBOY
Release: 2016-07-21 15:16:35
Original
918 people have browsed it

If you use the wrong method function or use it too little, or if the logical order of several method functions is wrong, it is likely to be a loophole, and it is not easy to find out. So confused~

Look online to see if any expert has come up with relevant conclusions, and sure enough, there is! But it doesn’t seem to be very comprehensive. I have improved it a little here for reference only.

Copy code The code is as follows:

// Judge between 0 and '', null, empty, false The relationship between
$a = 0;
echo "The relationship between 0 and '', empty, null, 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($a)){
echo "0 is empty;";
}else{
echo "0 is not empty;";
}
if( is_null($a)){
echo "0 is null;";
}else{
echo "0 is not null;";
}
if(is_numeric($a) ){
echo "0 is numeric;";
}else{
echo "0 is not numeric;";
}
if(is_string($a)){
echo "0 is string;";
}else{
echo "0 is not string;";
}
if(!$a){
echo "0 is false;" ;
}else{
echo "0 is not false;";
}
// Determine the relationship between '' and 0, null, empty, false
$a = ' ';
The relationship between echo "'' and 0, empty, null, false: ";
if($a == 0){
echo "'' == 0;";
}else{
echo "'' != 0;";
}
if(intval($a) == 0){
echo "intval('') == 0 ;";
}else{
echo "intval('') != 0;";
}
if(empty($a)){
echo "'' is empty ;";
}else{
echo "'' is not empty;";
}
if(is_null($a)){
echo "'' is null;";
}else{
echo "'' is not null;";
}
if(is_numeric($a)){
echo "'' is numeric;";
}else{
echo "'' is not numeric;";
}
if(is_string($a)){
echo "'' is string;";
}else{
echo "'' is not string;";
}
if(!$a){
echo "'' is false;";
}else{
echo " '' is not false;";
}
// Determine the relationship between null and '', 0, empty, false
$a = null;
echo "null and '', 0. The relationship between 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($a)){
echo "null is empty;";
} else{
echo "null is not empty;";
}
if(is_numeric($a)){
echo "null is numeric;";
}else{
echo "null is not numeric;";
}
if(is_string($a)){
echo "null is string;";
}else{
echo "null is not string;";
}
if(!$a){
echo "null is false;";
}else{
echo "null is not false;";
}
echo "";


The output result is:
PHP hollow string introduces the relationship between 0, null, empty and false_PHP tutorial

I think based on the output results, I can clearly solve the rough relationship between empty strings, 0, null, empty and false. During the development process, I can flexibly use the methods in the above code and add good logic. Basically, There should be no problems.

Click to download the relevant source code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325931.htmlTechArticleIf you use the wrong method function or use too little, if the logical order of several method functions is wrong, it is very likely that It's just a loophole, and it's not easy to find. I’m so confused~ Let’s look online to see which one is taller...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template