Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:29:51+00:00 2026-06-09T12:29:51+00:00

I’m thinking to use Array to store this tiny data instead using Database. But,

  • 0

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 :

  1. 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");
  1. 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:29:52+00:00Added an answer on June 9, 2026 at 12:29 pm

    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:

    $cities = array( 021 => "CityA", 031 => "CityA", 011 => "CityB")
    $couriers = array( "CityA" => array("FedEx", "TNT", "DHL"),
                       "CityB" => array("YYY Cargo", "USPS"),
                       "CityC" => array("UPS", "Regular Mail", "XXX Cargo"));
    

    So, in your example, for retrieving a courier for prefix 021 you can acces it like this:

    $city = $cities[$phone_prefix];
    $courier_key = array_rand($couriers[$city]);
    $courier_name = $couriers[$city][$courier_key];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.