Need a little help finding a substring

Hi,
I’m looking for array elements which contain a substring. Can someone help me understand why strpos will not find anything but an exact match? Thanks. Below is some sample code.

$data = array("ad1", "d2", "-d3");
$filters= array("d1");
$result=$filters[0]." Not Found";

foreach($data as $d){
	echo $d,", ";
	foreach($filters as $f){
		if(stripos($f,$d)!==false)
		{
			$result="found ".$f;
		}
	}
}
echo $result;

this exact code echoed out: ‘ad1, d2, -d3, d1 Not Found’

Just a note if you are copying and pasting into something like PHPTester.

The array elements need to be single quotes. I tried copying from this page back into PHPTester and I got warnings about using constants. So somehow pasting into this site or the other changed the quote types.

worked it out, but it seems backwards. its needle/haystack. I was looking for a needle in a haystack. It seems I need to look for a haystack in a needle, lol.

Sponsor our Newsletter | Privacy Policy | Terms of Service