0

Someone could explain me how these two exclamation points works?

<?php
      $foo = !!'foo'; 
      echo $foo;
?>
  • it prints `1`, because `'foo'` is true, and Not, Not foo is still true. In the same way that `$foo = !'foo';` prints noting which is typical of falsy values. – ArtisticPhoenix Apr 06 '18 at 23:53
  • further if you type cast `'foo'` to a boolean (which is basically what you are doing), `echo (bool)'foo';` it prints `1` So this is basically `echo !!(bool)'foo';` – ArtisticPhoenix Apr 06 '18 at 23:56
  • Fun note: `echo true;` outputs `'1'` and `echo false;` outputs `''`. [`var_dump()`](http://php.net/manual/en/function.var-dump.php) is the best choice for debug output. – Sammitch Apr 06 '18 at 23:56

0 Answers0