I'm making a website that has URLs for each country and city, and name of restaurant.
(www.domain.com/country/city/restaurant-name)
I know how to do the Apache rewrites for it,
The question is how to make it as efficient as possible wuth php.
right now what I do is first declare a two-dimensional array of countries and cities:
$countries = array("United-Kingdom"=>array("Bristol","London"),
"Italy"=>array("Rome","Milan","Napoli"));
than I check if the city exists:
if (isset ($countries[$page])
and then i do use the in_array function for the city, the restaurant name is looked up in the database.
The array of countries and cities is quite huge, so I want to know if there's a more efficient way of doing this.
I though of maybe making a php file for each country and try to include it, and have in each php file the array of cities. and maybe set up a cron job that will update the files.
I wondered is the most efficient way of doing this that will use the least processing CPU usage and make the server serve the pages as fast possible.
A faster way than using in_array would be to stick with isset(). You can structure your array like this:
$countries = array("United-Kingdom"=>array("Bristol"=>true,"London"=>true);
Then....
if(isset($countries[$country][$city])){
//...
}