PHP: Taking Array (CSV) And Intelligently Returning Information -


Hey everyone I'm the first time poster, but I've browsed this site many times I have a coding issue I'm not sure how to solve it really. First of all I want to explain what I have to do, and what information I have, and I hope someone can defeat me in the right direction by nudge.

I have a spreadsheet (CSV), the following information: Name of the zone, ZIP code, city name A zone should have several such cities, which fall under it, and each city has several zip codes that fall under it. For example:

Zone H, 92603, Irwin

Zone H, 9 00604, Irwin

Zone J, 92625, Corona

etc.

OK, now that the way out, what I have to do with this information here. I need to be able to input city name and I want to get that city Along with all the zip codes coming under, the city will also have to return. For example, if I input Chatsworth, then I should give it to me x) and (12345, 12346, 12347) as zip code (just one example).

I'm not sure that this is the best way to go about this. I can create a MySQL database and work from there, or just work from .csv files, or it can hardcod into a PHP file. I do not know how to find values ​​in the columns of an array, and then return the second column (specifically, many zip codes per city).

If someone can help me, then it is highly appreciated. Also, if I need more information from me then do not hesitate to tell me, thank you for reading all.

Zone H, 92603, Irwin

Jen H, 92604, Irwin

Zone J, 92625, Corona

etc.

You can take the file and can get all its contents. Then divide it by new line:

  $ searchCity = 'searched'; // or whatever city you are looking for $ file = file_get_contents ('file.csv'); $ Result = array (); $ Line = explosion ("\ n", $ file); // Any line delay is used on 1 param, when deciding on // im but how idk is your file encoded forehack ($ Lines as $ line) {// line $ col = explode (",", $ Line split); // And you know that the city is the third element if (trim ($ col [2]) == $ searchCity) {$ result [] = $ col; }}   

And finally you have an array of such results:

  $ results = array (array ('zone b', '12345' , 'Search'), array ('zone z', '35145', 'finder'), array ('zone que', '12365', 'searched'),)    

Comments