Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
var_dump(1 == '1');
var_dump(1 === '1');
var_dump(0 == 'a');
var_dump('1' == '01');bool(true) bool(false) bool(false) bool(true)
- Expecting
0 == 'a'to be true, as in PHP 7: since PHP 8 a number compared with a non-numeric string is turned into a string, and'0'is not'a'. - Expecting
'1' == '01'to be false because the strings differ: under==two numeric strings compare as numbers, and only===compares them as text.
- What does
var_dump('abc' == 0)print on PHP 7 and on PHP 8? - Why is
'1e3' == '1000'true?