Comparator difference in php [duplicate]

0

What's the difference between the following codes in php?

 if ($resultado_barganha->tipo === "t") { }

E:

if ($resultado_barganha->tipo == "t") { }

From what I've noticed they do the same thing. However netbeans recommends === why?

    
asked by anonymous 19.05.2016 / 22:26

3 answers

2

== checks to see if the conditions that were compared are the same, regardless of type, eg

if(true == true) // Verdadeiro
if(true == 1) // Verdadeiro

=== It checks whether the conditions are equal and also checks the type, ie both the information and the type must be the same, eg

if(true === true) // Verdadeiro
if(true === 1) //Falso
if(1 == 1) //Verdadeiro

Returns false because 1 is integer and true is not integer type but boolean

    
19.05.2016 / 22:35
1

When using == it is only checked if the two values are equal.

But when you use === is checked if the two values are equal and if there is no information it will be set to "t", I have never used it with a string, I usually use it to do for example:

if ($ result_bargain-> type === false) {}

    
19.05.2016 / 22:30
1

According to the document:

$a == $b    Igual   Verdadeiro (TRUE) se $a é igual a $b.

$a === $b   Idêntico    Verdadeiro (TRUE) se $a é igual a $b, e eles são do mesmo tipo.

There is no better explanation than this, at least I think.

Reference

    
19.05.2016 / 22:30