Keren Keren - 2 months ago 8
PHP Question

weirdly if else compares wrongly

$comet = $this->model->getActiveComet($userId);
$string = 'notificationComet';

if ($comet !== $string) {
echo $comet;
echo $string;
echo "yes";exit;
}


as shown in the code above, only if value of
$comet
doesn't match
$string
it should execute whatever inside the braces thus exit.

But both of them are having the same value which is 'notificationComet'

I tested gettype() of both variables and they return string as type.

I used
!=
instead of
!==
, no difference.

if I change the condition to this:
if ($comet === $string)
the block inside doesn't get executed.

I just don't understand why the condition is
true
for
if ($comet !== $string)
as they both hold the same value?

Please explain to me someone where I made mistake?

Answer

Try to use the following...

$comet = $this->model->getActiveComet($userId);
$string = 'notificationComet';

if ( strpos($comet,$string) === FALSE ) {
    echo $comet;
    echo $string;
    echo "yes";exit;
  }

I believe that would work.