112233
112233

Reputation: 2466

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?

Upvotes: 0

Views: 41

Answers (1)

Emz
Emz

Reputation: 542

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.

Upvotes: 2

Related Questions