How to find array values is present in a string of shuffled letters.

$string = "ankegsrdib";
$words = array("ask","bird","egg");

which function should I use to find this.? Also the result should be like this

array("ask"=>"Yes","bird"=>"Yes","egg"="No")

please suggest some ideas.

Not sure how you.d use strspn with the op.s remit. I.d use a loop with strpos and fill the output array in the loop. The array functions used to be really slow so looping was the preferred method. Haven.t checked out the php7 speeds. Perhaps array functions have caught up?

$ans = [];
foreach($words as $word)  $ans[$word] = (strpos($string, $word) !== false) ? 'Yes' : 'No';
print_r($ans);

Edited 1 Week Ago by diafol