I’m thinking to use Array to store this tiny data instead using Database. But, I have difficulties to ‘call’ the data since this is Multi Dimensional Array.
Here’s my situation :
- I have several phone prefix from different cities :
$CityA = array("021","031","041","051"); $CityB = array("011","012","013","014"); $CityC = array("111","112","113","114");
- Also, I have several courier for those cities :
$CityA = array("FedEx", "TNT", "DHL"); $CityB = array("YYY Cargo", "USPS"); $CityC = array("UPS", "Regular Mail", "XXX Cargo");
what I need is :
INPUT : Phone Prefix, for example 021
OUTPUT : FedEx, TNT or DHL >> Randomly selected
here’s another examples :
012 >> YYY Cargo (Randomly selected from “YYY Cargo”, “USPS”)
112 >> UPS
etc.
It’s pretty easy with MySQL, but I want to reduce database connection by using Array. how to do this?
You should use associative arrays for easier access. Since you want to access info by phone prefix, you should use these as keys for the first array. Then, your second array can be indexed by city, as below:
So, in your example, for retrieving a courier for prefix 021 you can acces it like this: