Php equal sign (=) and full equal sign (=), php equal sign all

Source: Internet
Author: User

Php equal sign (=) and full equal sign (=), php equal sign all


<? Php

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

}
Echo "<br/> when person001 and person003 are the same object, they are all *************** <br/> ";
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 "<br/> array and array2 are not the same array, but the content is the same, all ************** <br/> ";
If ($ array = $ array2)
{
Echo "array = array2 ";
} Else
{
Echo "array! = Array2 ";
}
Echo "<br/> array and array3 are not the same array, but the content is the same, all ************************ <br/> ";
If ($ array ===$ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo "<br/> array and array3 are not the same array and their content is different, not all *********************** <br/> ";
$ Array3 [0] = 0;
If ($ array ===$ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo "<br/> ";
// (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 "<br/> after the same data type, if it is of four scalar types (boolean, integer, float, string ), if the value is the same, true or false <br/> ";

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

}
Echo "<br/> ";
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 "<br/> is not of the same type as false ********************** * ********* <br/> ";
If ($ nums = true)
{
Echo "nums = true ";
} Else
{
Echo "nums! = True ";

}
Echo "<br/> ";
If ($ person001 === true)
{
Echo "person001 = true ";
} Else
{
Echo "person001! = True ";

}

?>




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


<? Php
Require_once 'person. php ';
Header ("content-type: text/html; charset = UTF-8 ");
$ Person001 = new Person ("wuxifu", 110 );
$ Person002 = new Person ("wuxifu", 110 );
$ Person003 = $ person001;
// Wait (=) to judge whether the data type is the same first. If the equal sign has one side of the boolean type, the other side is converted to the boolean type, otherwise, the data type on the right of the equal sign is forcibly converted to the data type on the left.
// (1) if it is an object after the same data type (true if the content of the two objects is the same)
Echo "<br/> when person001 and person002 are not the same object, but the content is the same as ************* <br/> ";

If ($ person001 = $ person002)
{
Echo "person001 = same content as person002 ";
} Else
{
Echo "person001! = Different person002 content ";

}
Echo "<br/> when person001 and person003 are the same object (the same content ), *************** <br/> ";
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 "<br/> array and array2 are not the same array, but the content is the same, ************** <br/> ";
If ($ array = $ array2)
{
Echo "array = array2 ";
} Else
{
Echo "array! = Array2 ";
}
Echo "<br/> array and array3 are not the same array, but the content is the same, ************************ <br/> ";
If ($ array = $ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo "<br/> array and array3 are not the same array and their content is different, not equal to ********************** <br/> ";
$ Array3 [0] = 0;
If ($ array = $ array3)
{
Echo "array = array3 ";
} Else
{
Echo "array! = Array3 ";
}
Echo "<br/> ";
// (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 "<br/> after the same data type, if it is of four scalar types (boolean, integer, float, string ), if the value is the same, true or false <br/> ";

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

}
Echo "<br/> ";
If ($ nums = $ nums3)
{
Echo "nums = the same value as nums3 ";
} Else
{
Echo "nums! = Nums3 values are different ";

}
// (4) Not the same data type. If one side of the equal sign has a boolean value, the other side is converted to the boolean type, otherwise, the data type on the right of the equal sign is converted to the data type on the left of the equal sign.
Echo "<br/> is not the same data type. If one side of the equal sign has a boolean value, the other side is converted to a boolean type, otherwise, the data type on the right of the equal sign is changed ***************************** * ** <br/> ";

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

}
Echo "<br/> ";
If ($ person001 = true)
{
Echo "person001 = true ";
} Else
{
Echo "person001! = True ";

}
Echo "<br/> ";
If (true = $ nums)
{
Echo "true = nums ";
} Else
{
Echo "true! = Nums ";

}
Echo "<br/> ";
If (true = $ person001)
{
Echo "true = person001 ";
} Else
{
Echo "true! = Person001 ";

}
Echo "<br/> ";
If ($ array = $ person001)
{
Echo "array = person001 ";
} Else
{
Echo "array! = Person001 ";

}
Echo "<br/> ";
If ($ array = true)
{
Echo "array = true ";
} Else
{
Echo "array! = True ";

}

?>


What are the three equal signs in php? ===

1. =: Value assignment, which is also valid during logical operations;

2. =: equal to the calculation but not the comparison value type;

3. =: Completely equal to the operation. Not only is the value compared, but also the type of the value. Only when the two are consistent is true.

Why are there two equal signs ???

A = B; indicates a logical expression. It is used to judge whether the values of a and B are equal. If they are equal, the expression a = B is equivalent to true. If they are not equal, it is equivalent to false.
A = B; it is a value expression that assigns the value of variable B to.

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.