Php equality ()-php Tutorial

Source: Internet
Author: User
Php equality () Require_once 'person. php ';
Header ("content-type: text/html; charset = utf-8 ");
$ Person001 = new Person ("wuxifu", 110 );
$ Person002 = new Person ("wuxifu", 110 );
$ Person003 = $ person001;
// Equality (=) indicates that the data type must be the same first. if the data type is different, the value is false.
// (1) if it is an object after being of the same data type (true if it is the same object)

Echo"
If person001 and person002 are not the same object, they are not all *************
";
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 all **************
";
If ($ person001 ===$ person003)
{
Echo "person001 === person003 is the same object ";
} Else
{
Echo "person001! = Person003 is not the same object ";

}
// (2) after the same data type, if it is an array (if the content is the same, true or 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. they are all *************
";
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. they are all ************************
";
If ($ array ===$ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo"
Array and array3 are not the same array, and the content is different. they are not complete ***********************
";
$ Array3 [0] = 0;
If ($ array ===$ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo"
";
// (3) after the same data type, if it is four scalar types (boolean, integer, float, string), if the value is the same, true or false
Echo"
If it is of the same data type (boolean, integer, float, string) and the value is the same, true or false
";

$ Nums = 110;
USD nums2 = 120;
$ Nums3 = 110;
If ($ nums ===$ nums2)
{
Echo "nums = the same value as nums2 ";
} Else
{
Echo "nums! = Different nums2 values ";

}
Echo"
";
If ($ nums ===$ nums3)
{
Echo "nums = the same value as nums3 ";
} Else
{
Echo "nums! = Different nums3 values ";

}
// (4) false if the data type is not the same
Echo"

********************************
";
If ($ nums = true)
{
Echo "nums = true ";
} Else
{
Echo "nums! = True ";

}
Echo"
";
If ($ person001 === true)
{
Echo "person001 = true ";
} Else
{
Echo "person001! = True ";

}
?>

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.