Using php, I tried to check whether a certain string contains some characters.
I used this code, which evaluates to false
:
$string1 = 'Hello World!';
if (strpos($string1, 'hel')) {
echo 'True!';
}
I did a quick google search and found this variation:
$string1 = 'Hello World!';
if (strpos($string1, 'hel') !== false) {
echo 'True!';
}
Which works and evaluates to true
.
What is the actual difference between them and why the first one evaluates as false
and the second as true
?
Thanks!