0

I am studying PHP, and I find, if use === to compare the variable:

<?php 

    $x = "100";
    $y = 100;
    var_dump($x===$y);  // print bool(false)
?> 

But if I use the below:

<?php 

    $x = "100";
    $y = '100';
    var_dump($x===$y);  // print bool(true)
?> 

So, someone can explain why it return false and true in the example above?

s-n-2
  • 405
  • 1
  • 6
  • 24

1 Answers1

0

The === compares the variable type and the value. In example one you have a string against an integer, these don't match. Example two you have a string against a string, these match.

See: https://3v4l.org/Jgohi4

For more information: http://php.net/manual/en/language.operators.comparison.php

TRUE if $a is equal to $b, and they are of the same type.

chris85
  • 23,846
  • 7
  • 34
  • 51