Hello purples. I'm working on a project that wants to compare two arrays and display all matches. I'm almost there... comparing two arrays seems to be working, but only one piece of the match is displaying. List1 is a database field looking at ingredients that are entered by the user. List2 is a list of toxic ingredients. When a user enters a word that matches the list of toxics (list2) that word is displayed on the Web page. However only ONE of the matched words displays - when there are more than one matches.
Anybody run into this?
$list1 = $row['ingredients'];
$list2 = array("2-butoxyethanol","acetone","ammonia","aerosol","bleach","butylcellosolve","d-limonene","DEA","diethyleneglyco","diethanolamine","ethoxylatednonylphenol","formaldehyde","fragrance","methylenechloride","monoethanolamine","morpholine","NPE","NTA","naphthalene","nonylphenolethoxylate","paraben","paradichlorobenzene","perchloroethylene","petroleum","phosphate","phosphoricacid","silica","sodiumdichloroisocyanuratedihydrate","sodiumhypochlorite","sodiumlaurylsulfatetoluene","trisodiumnitrilotriacetate","turpentine","xylene");
$tmp1 = explode(',',$list1);//ingredients
$tmp2 = explode(',',$list2);//toxics
for($i = 0; $i <count($tmp1); $i++){
$pieces = $tmp1[$i];
if (in_array($pieces, $list2)) {
echo "<span style=\"color:red;\">Toxics exist: " . $pieces . "</span>";
}
}