There are two arrays having sttings. I need to get all the strings from the first array, which have got any string from the array 2, in whole or in part within them.
E.g.
Array $combi
cater
bater
sater
Array $words
cat
mat
bat
lat
tat
hat
so, i should get from array 1
cater (becuase it has the word \'cat\')
bater (becuase it has \'bat\')
to accomplish this, i wrote the following simple piece of code..and it works. The problem is that my second array - $words is BIG, with atleast 30000 elements or words. So this piece of code takes a lot of time, and usually times out.
What is a better and faster way to do this?
$c=count($combi)-1;
$w=count($words)-1;
for ($i=0;$i<=$c;$i++) {
for ($j=0;$j<=$w;$j++) {
if (eregi (trim($words[$j]),trim($combi[$i]))) {
echo \">>\".$combi[$i].\" \".$words[$j].\"<br>\";
}
}
}
Thanks.
Saurabh Kumar