Sunday, 18 August 2013

Look for several characters in a string and get back an array of characters that are in the string?

Look for several characters in a string and get back an array of
characters that are in the string?

Say I have the string:
$s = "ABCDEFGEHIJ";
and an array:
$a = array("2", "7", "A", "E", "J", "W", "Z");
How can I search $s to see if the characters in $a exist, then return an
array with all characters that do? So I would get the result:
$result = array("A", "E", "J");
I've tried strpos($s, "A"); but this only works for a single string and
returns the position so it doesn't fulfill the criteria. How would SO do
it?

No comments:

Post a Comment