I need to match values in Needle & Haystack arrays, using alternate Ontology values when relevant. This syntax works, however I would like to know if there is a more efficient way to do this as I will be using it for several corresponding $AltNeedle arrays for each of 1000+ $needles and $haystack arrays.In my use case, the Needle & Haystack correspond with Product and Customer attributes respectively, and matches are made and ranked by assessing thousands of attributes for each, and attributes often have an array of values. One way in which Alt. Values are used are to incorporate closely related values into certain match results.<?php$needles = ['John', 'Alex', 'Pam'];$haystack = ['John','Alexander','Kim', 'Michael'];$AltNeedle = ['Alexander', 'Alex', 'Alexi'];foreach ($needles as $current_needle) {    if (in_array($current_needle, $AltNeedle) ) { // Exists in $AltNeedle        foreach ($AltNeedle as $current_AltNeedle) {                if (in_array($current_AltNeedle, $haystack) ) { // Compares $current_AltNeedle to $haystack                    echo $current_AltNeedle. True; ;                }         } // Ends $AltNeedle foreach    }    elseif (in_array($current_needle, $haystack) ) {        echo $current_needle.: True; ;    }    else {        echo $current_needle.: False; ;    }                  } // End foreach?>RESULT:John: True; Alexander True; Pam: False;
Matching Needle & Haystack values using alternate Ontology values
php