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

  • SEARCH
  • Home
  • 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 5839121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:32:34+00:00 2026-05-22T11:32:34+00:00

What I am trying to do is explode some strings from MySQL by /,/,

  • 0

What I am trying to do is explode some strings from MySQL by /,/, and then somehow be able to refer to these arrays outside of the loop.

This is because, each region, country and province are listed in the $data array in the appropriate order, and I need to glue them together somehow.

For example, inside MySQL there is a string stored as:

Regions: Africa, Balkans, South America
Countries: Uganda, Greece, Brazil
Provinces: Ubuge, Athenos, Santa Catarina

But I am having a really hard time trying to imagine how to tie these together, remember that sometimes there is only one member in each array, or there can be up to a hundred. But each array always contains the same number.

My attempt is something like this… I can get them to print like this, but I can’t save them to use outside of the loop.

  for ($i = 0; $i < $numrows; $i++){

            $provinces = explode(',', $data[$i]['provinces']) ;
            $countries = explode(',', $data[$i]['countries']) ;
            $regions = explode(',', $data[$i]['regions']) ;       

            foreach($countries as &$country){

            echo $country;

                }
}

Any ideas or help would be appreciated.

What I would like to have the final product look like would be

Place:

Africa --- Uganda --- Ubuge
Balkans --- Greece --- Athenos
South America --- Brazil --- Santa Catarina
  • 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-05-22T11:32:34+00:00Added an answer on May 22, 2026 at 11:32 am

    Hmm, an associative array might be a good solution for this, if I understand your issue:

    $region_list = array();
    
    for ($i = 0; $i < $numrows; $i++){    
         $provinces = explode(',', $data[$i]['provinces']) ;
         $countries = explode(',', $data[$i]['countries']) ;
         $regions = explode(',', $data[$i]['regions']) ;       
    
         // So we don't have to run count every time in the loop
         $length = count($countries);
    
         // Since it's based of the same numeric index
         for($j = 0; $j < $length; $j++)
            $region_list[$regions[$j]] = array(
              'province' => $provinces[$j],
              'country' => $countries[$j]);
         }
    }
    
    // Now to loop through all our data
    // For an associative array, we can loop over key => value so $region
    // becomes the region name
    foreach($region_list as $region => $data) {
       echo "$region --- {$data['country']} --- {$data['province']}";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove some excessive indention from a string, in this case it's
.NET balanced group regexes make my head explode. I've got this string i'm trying
I'm trying to get some information from ebay api and store it in database
its when i starting trying implementing this that i got quite stuck. some business
I've been going bananas trying to get some data from Javascript on one page
im having some problems trying to read a SQlite data base from flash using
I asked this question earlier and am now trying to explore the idea of
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to get my css / C# functions to look like this: body {
Trying to find some simple SQL Server PIVOT examples. Most of the examples that

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.