I've got an array of values, all containing one word, and I'd like to be able to find which of those values is found first in a string.
$materials = array("cotton","silk","polyester","denim","wool");
$string1 = "The fabric composition of this jacket is 100% cotton (body) and 65% polyester / 35% cotton (lining)";
$string2 = "The jeans are made from denim with cotton pockets";
So for the $string1, I'd like it to say that it found 'cotton' first as the material and for the $string2 I'd like it to say that it found 'denim' first.
Do you know a way of doing this? I was originally looking at a foreach loop but it would go in order of the array meaning it would also bring 'cotton' back for both strings as that's the first one in the array:
foreach ($materials as $material) {
if (stripos($string1, $material) !== FALSE) {
$product_material1 = $material;
break;
}
}