Home  >  Article  >  Backend Development  >  PHP equal sign (==) and congruence (===)_PHP tutorial

PHP equal sign (==) and congruence (===)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:27887browse

php equal sign (==) and congruence (===)


require_once "Person.php';
header("content-type:text/html;charset=utf-8");
$person001=new Person("wuxifu", 110);
$person002=new Person("wuxifu", 110);
$person003=$person001;
//To determine congruence (===), the data types must be the same first. If the data types are different, it will be false
//(1) After it is the same data type, if it is an object (if it is the same object, it is true, otherwise it is false)

echo "
When person001 and person002 are not the same object, they are not congruent******************
";
if($person001===$person002)
{
echo "person001===person002 is the same object";
}else
{
echo "person001!==person002 is not the same object";

}
echo "
When person001 and person003 are the same object, they are congruent**************
";
if($person001===$person003)
{
echo "person001===person003 is the same object";
}else
{
echo "person001!==person003 is not the same object";

}
//(2) is the same data type, if it is an array (if the contents are the same, it is true, otherwise it is false)
$array=array(110,120,130);
$array2=array(110,120,130);
$array3=$array;
echo "

array and array2 are not the same array, but the content is the same, congruent**********
";
if($array===$array2)
{
echo "array===array2";
}else
{
echo "array!==array2";
}
echo "
array and array3 are not the same array, but the content is the same, congruent**********************
";
if($array===$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
array and array3 are not the same array, and their contents are also different. They are not congruent************************
";
$array3[0]=0;
if($array===$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
";
//(3) After they are the same data type, if they are four scalar types (boolean, integer, float, string), if the values ​​are the same, it will be true; otherwise, it will be false
echo "
is the same data type. If it is four scalar types (boolean, integer, float, string), the value is the same, then it is true, otherwise it is false
";

$nums=110;
$nums2=120;
$nums3=110;
if($nums===$nums2)
{
echo "nums===nums2 has the same value";
}else
{
echo "nums!==nums2 values ​​are different";

}
echo "
";
if($nums===$nums3)
{
echo "nums===nums3 has the same value";
}else
{
echo "nums!==nums3 values ​​are different";

}
//(4) is not the same data type, then it is false
echo "

is not the same type, false is not congruent************************************
";
if($nums===true)
{
echo "nums===true";
}else
{
echo "nums!==true";

}
echo "
";
if($person001===true)
{
echo "person001===true";
}else
{
echo "person001!==true";

}

?>




**************************************************** ******************


require_once "Person.php';
header("content-type:text/html;charset=utf-8");
$person001=new Person("wuxifu", 110);
$person002=new Person("wuxifu", 110);
$person003=$person001;
//Etc. (==) first determines whether the data types are the same. If they are different, if one side of the equal sign is a boolean type, the other side will be converted to a boolean type. Otherwise, the data on the right side of the equal sign will be forced to be converted to the data on the left. Type
//(1) After it is the same data type, if it is an object (as long as the contents of the two objects are the same, it is true, otherwise it is false)
echo "
person001 and person002 are not the same object, but the content is the same****************
";

if($person001==$person002)
{
echo "person001==person002 has the same content";
}else
{
echo "person001!=person002 has different content";

}
echo "
When person001 and person003 are the same object (the same content), wait for ******************
";

if($person001==$person003)
{
echo "person001==person003 is the same object";
}else
{
echo "person001!=person003 is not the same object";

}
//(2) is the same data type, if it is an array (if the contents are the same, it is true, otherwise it is false)
$array=array(110,120,130);
$array2=array(110,120,130);
$array3=$array;
echo "

array and array2 are not the same array, but the content is the same, etc.******************
";

if($array==$array2)
{
echo "array==array2";
}else
{
echo "array!=array2";
}
echo "
array and array3 are not the same array, but the content is the same, etc.**********************
";

if($array==$array3)
{
echo "array==array3";
}else
{
echo "array!=array3";
}
echo "
array and array3 are not the same array, and the contents are also different, not equal to************************
";

$array3[0]=0;
if($array==$array3)
{
echo "array===array3";
}else
{
echo "array!==array3";
}
echo "
";
//(3) After they are the same data type, if they are four scalar types (boolean, integer, float, string), if the values ​​are the same, it will be true; otherwise, it will be false
echo "
is the same data type. If it is four scalar types (boolean, integer, float, string), the value is the same, then it is true, otherwise it is false
";

$nums=110;
$nums2=120;
$nums3=110;
if($nums==$nums2)
{
echo "nums==nums2 has the same value";
}else
{
echo "nums!==nums2 values ​​are different";

}
echo "
";
if($nums==$nums3)
{
echo "nums==nums3 has the same value";
}else
{
echo "nums!=nums3 values ​​are different";

}
//(4) are not the same data type. If there is a boolean type value on one side of the equal sign, convert the other side to the boolean type. Otherwise, the data on the right side of the equal sign will be converted into the data on the left side of the equal sign. Type
echo "

is not the same data type. If there is a boolean value on one side of the equal sign, convert the other side to the boolean type. Otherwise, the data type on the right side of the equal sign will be converted to the data type on the left side of the equal sign** ******************************
";

if($nums==true)
{
echo "nums==true";
}else
{
echo "nums!=true";

}
echo "
";
if($person001==true)
{
echo "person001==true";
}else
{
echo "person001!=true";

}
echo "
";
if(true==$nums)
{
echo "true==nums";
}else
{
echo "true!=nums";

}
echo "
";
if(true==$person001)
{
echo "true==person001";
}else
{
echo "true!=person001";

}
echo "
";
if($array==$person001)
{
echo "array==person001";
}else
{
echo "array!=person001";

}
echo "
";
if($array==true)
{
echo "array==true";
}else
{
echo "array!=true";

}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847855.htmlTechArticlephp equal sign (==) and congruent (===) require_once "Person.php'; header( "content-type:text/html;charset=utf-8"); $person001=new Person("wuxifu", 110); $person002=new Person("wuxifu", 110); $...
Statement:
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