Var_dump (0 == 'all'); // WHY IS TRUE

I do not understand below conclusion. expressions found below in the php.net manual in the boolean section.

<?php var_dump(0 == 'all');// IS bool(true) var_dump((string)0 == 'all'); //IS bool(false) var_dump(0 === 'all'); // //IS bool(false) ?> 
+6
source share
1 answer

If you compare an integer with a string, each string is converted to a number, therefore:

 (0 == 'all') -> (0 == 0) -> true 

Type conversion does not occur when a comparison === or !== , as this also includes a type comparison:

 (0 === 'all') -> (integer == string) -> false 

The second line of code you wrote forces the integer value to be considered a string, so the numeric value is not executed.

+8
source

Source: https://habr.com/ru/post/980300/


All Articles