I have this really basic PHP code I can't figure out. In the example below, why do I get 'MATCH' when $i = 0, and not for the remaining rows …? It seems to be possible to workaround by using === instead of ==, but I can't understand why.
<?php
$text = 'foo bar';
for ($i = 0; $i <= 5; $i++) {
echo '<p>' . $i . ': ';
if ($i == $text) {
echo 'MATCH!';
} else {
echo 'NOPE';
}
}
?>
source https://stackoverflow.com/questions/67731189/string-comparison-in-php-doesnt-make-sense
Comments
Post a Comment