PHP Question: What is an easy way to sort values gathered from a spreadsheet?

Tom C

New member
I'm creating a page where a user can enter their zip code, and the web page will shoot back the 0 to 20 real estate agents closest to them (the 20 closest within 50 miles). I'm new to PHP, and if anyone has advice for me I would be very appreciative.

I've got two .csv files. One has every zip code in California along with latitude and longitude coordinates. The other is a list of agents with their zip code. When the user enters their zip code, I use a loop to go through the entire csv file until a match is found and the lat/long is stored.

What I'm not sure of is the best way to program the rest. Should I just have another loop that reads the zip code of each agent, and then searches the other csv file for the correct lat/long, and then calculate the distance between the two? If so, is there an easy way to sort the agents by distance using an array of some kind?

Right now my only idea is to define 20 separate variables, and then sort those, but I'm guessing there is a smarter way to do it.

Any thoughts?
 
Back
Top