elepil
asked on
Can somebody explain the result of this if-statement?
$server = "localhost";
if (strpos($server, "ddd") >= 0) {
echo "Substring was found<br/>";
}
else {
echo "Substring was NOT found<br/>";
}
if (strpos($server, "localhost") >= 0) {
echo "Substring was found<br/>";
}
else {
echo "Substring was NOT found<br/>";
}
Can somebody please explain to me why, regardless of whether the $needle is "ddd" or "localhost", the TRUE block of the IF statement is the one executing?
BOTH True statements execute you mean? You have two separate if statements there.
please refer to the explanation in your previous question, and again to this page:
http://php.net/manual/en/types.comparisons.php
only === will match on the data type (first) AND then on the value.
so, if the data type does not match (boolean is not a number), it will not match, even if with == the implicitly converted values would match
http://php.net/manual/en/types.comparisons.php
only === will match on the data type (first) AND then on the value.
so, if the data type does not match (boolean is not a number), it will not match, even if with == the implicitly converted values would match
ASKER
As more experienced PHP developers than I am, can you show me the actual code you would do to test strpos() whether or not it successfully found the substring? That is really all I'm trying to do. Being provided a link to a long tutorial article that covers more than what I'm trying to accomplish is frustrating and will not get credit.
I am accustomed to other classic OOP languages like Java, and it frustrates me that something this simple is not simple in PHP.
I am accustomed to other classic OOP languages like Java, and it frustrates me that something this simple is not simple in PHP.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your responses.