-4

There is a simple example to understand the difference between loose comparison == and strict comparison === in PHP?

ViDiVe
  • 134
  • 1
  • 10

1 Answers1

1

This is an easy example to understand the differences between loose and strict comparison

<?php
$var1 = 100;
$var2 = "100";

// loose comparison does not contemplate the data type
// so the integer 100 is equal to string "100"
$comparison = ($var1 == $var2); // true
var_dump($comparison);

// strict comparison contemplates the data type
// so the integer 100 is different to string "100"
$comparison = ($var1 === $var2); // false
var_dump($comparison);
ViDiVe
  • 134
  • 1
  • 10