=== & !==
Moderator: General Moderators
Besides comparing variable values, it compares the variable types too.
Code: Select all
$int = 123;
$string = '123';
if ($int === $string) {
echo "something's wrong";
} else {
echo "nothing wrong";
}
if ($int == $string) {
echo "nothing wrong";
} else {
echo "something's wrong";
}- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
They are comparison and bitwise operators...
Read the manual at http://www.php.net/ for more insight but basically they mean:
Read the manual at http://www.php.net/ for more insight but basically they mean:
Code: Select all
//Comparisons
== Is the same as
!= Not the same as
=== Identical to
!== Not identical to
//Bitwise
&& AND
|| ORa more real life example 
in the case the operation succeeds and 0 items are processed, the function will return 0. However if you write fe:
The 0 will be evaluated to false.. And thus the code in the brackets will be executed... Therefore you have to test explicitely
Code: Select all
function dostuff()
{
// returns false if stuff failed
// otherwise returns the number of processed items
}Code: Select all
if (!dostuff()) { // operation was not a success }Code: Select all
if (dostuff() !== false) { // operation was succes }