vendredi 8 novembre 2019

PHP: if Statement using && give unexpected results

I have the following two variables with the exact same value:

$appointment->date->format('H:i') is equal to '13:00:00'
$hour->format('H:i') is equal to '13:00:00'

So when I do

if($appointment->date->format('H:i') == $hour->format('H:i'))
{ $result = true} else { $result = false}

It returns $result true

I also have another pair of variables with the exact same value:

$appointment->employee->user->firstname = 'Angela'
$employee->firstname == 'Angela'

Again, when I do:

if($appointment->employee->user->firstname == $employee->firstname)
{ $result = true} else { $result = false}

The variable $results returns true

So, both statements give back TRUE

Notice that I am using == and not === But now if I do:

if($appointment->date->format('H:i') == $hour->format('H:i') 
&&
$appointment->employee->user->firstname == $employee->firstname)
{ $result = true} else { $result = false}

The variable $result returns FALSE!

In my understanding, if both statements are true should be:

TRUE & TRUE => TRUE

But in this case is returning me FALSE. Why?

Aucun commentaire:

Enregistrer un commentaire