Hello, first time poster here. I just started learning PHP and HTML a month ago. I am trying to figure out a more efficient way to compare two large arrays. I am reading in a text file provided by a third party, exploding into a two dimensional array, and then doing some string manipulations to some of the fields. This text file has anywhere from 20,000 to 25,000 lines, and 10 “columns”. One of the columns is an item ID. I want to compare that column to another array of item IDs pulled from a mySQL database. However that array has about 4000 unique item IDs in it. I can loop through each of the 20,000 items and compare it to each of the 4000 item IDs, but that is 80 million comparisons. What I am trying to do is go through the 20,000 item array and if the item ID matches one of the 4000 unique IDs keep it, and drop the mismatches. The 4000 unique item IDs are numerical, however they aren’t exactly sequential. Over the years, item IDs have been decommissioned and are no longer used. So I can’t just start in the middle and do > or < and recursively keep cutting the group in half to find the item ID. If you have any ideas I’d really appreciate it.
have a look at array_intersect (http://us.php.net/manual/en/function.array-intersect.php) and array_search (http://us.php.net/manual/en/function.array-search.php
I would just set the item id as the key for the array
using isset($array[$key]) would be faster than any array search