$haystack = 'I am a haystack. Hear me rawr.';
$pos = strlen($haystack);
$nlen = 1;
$needle = array('.', '. ');
print_r(in_array(substr($haystack, $pos, $nlen), $needle, true));
I am having trouble figuring out why this is failing. I am trying to see if an array of needles matches the result that substr chooses from the haystack? How can I return that value as boolean?
Yes & NO because
substrreturns a string which is needle in your case and FALSE on failure in which case it won’t be a valid argument toin_arrayfunction.You should first extract a part of string using
substrand need to make sure that you extracted some string and it did not returnFALSE, only then you should use it inin_array.