View Single Post
  #1  
Old 06-10-2009, 06:55 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Efficient way to match unordered arrays?

I have a function which I am entering an array, and the job of the function is to match the entered array to an array within the list. It looks a little something like this...

PHP Code:
function Testarry ) {
  
temp.list = {
  {
"Test One""Test Two"},"String One",
  {
"Test Three""Test One"},"String Two",
  {
"Test Three""Test Two"},"String Three"
  
};
  
//matching script should go here
  
return appropriate string;

Thing is I can't compare them directly. Because the fed array may be in a different order. For example, if 'arry' is {"Test Two", "Test One"} I still need it two return "String One".
If there are no matches, OR if 'arry' contains a match but has extra items which are not in the list (i.e {"Test One", "Test Two", "Test Three"}) it should return false.

I could probably do some magic and come up with a way to match these, but I'd like to see some of your ideas to match them as there is probably a much better way then what I would do.

Thanks
Reply With Quote