0

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.

3
Contributors
4
Replies
48
Views
2 Months
Discussion Span
Last Post by diafol
0

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?

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

Edited by diafol

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.