Jump to content



Recommended Posts

$haystack = ",18,19,42,";
$needle = ",18,";
if (strpos($haystack,$needle)) {
	echo 'TRUE';
} else {
	echo 'FALSE';

This returns FALSE. 

What am I missing?


Edited by niche
Link to comment
Share on other sites

The problem is in the function name 'strpos' being at the beginning, the position will be 0, so 0 will be treated as false. The position of needle text placed anywhere but the beginning will be greater than 0, meaning true.

You need to check against not being false within the if condition and make sure you use !== compared to != with single equals symbol.


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...