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 8339233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:49:48+00:00 2026-06-09T04:49:48+00:00

I have a multidimensional array from a a MySQL database call. It looks something

  • 0

I have a multidimensional array from a a MySQL database call. It looks something like this:

array(2) { 
    [0]=> array(4) { 
        ["STATE"]=> "1" 
        ["COUNTY"]=> "101" 
        ["NEIGHBORHOOD"]=> "111111"
    }

    [1]=> array(4) { 
        ["STATE"]=> "2" 
        ["COUNTY"]=> "201" 
        ["NEIGHBORHOOD"]=> "222222"
    }

    [2]=> array(4) { 
        ["STATE"]=> "1" 
        ["COUNTY"]=> "201" 
        ["NEIGHBORHOOD"]=> "111111"
    }
}

I need to be able to get the neighborhood values for every county in every state that appears in the array. The data structure is that the neighborhood number is unique to the county, which is unique to the state.

I am thinking about creating an array for each county in each state, but I am not sure how to go about finding all the the values of neighborhood when state and county are identical.

Per the request in the comments, I have a DB with the information for the STATE, COUNTY, NEIGHBORHOOD, LATITUDE, LONGITUDE. I am using the following SQL Statement to get all NEIGHBORHOODS within a user selected radius of a user inputed location.

"SELECT `STATE` ,  `COUNTY` ,  `NEIGHBORHOOD`,((ACOS(SIN($lat* PI() / 180) * SIN(`LATITUDE` * PI() / 180) + 
         COS($lat* PI() / 180) * COS(`LATITUDE` * PI() / 180) * COS(($long- `LONGITUDE`) * 
         PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance
         FROM `censustracts` 
         HAVING distance<='$radius';"

These NEIGHBORHOODS can be in different STATES and COUNTIES, and I have no way of knowing 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-09T04:49:49+00:00Added an answer on June 9, 2026 at 4:49 am

    Perhaps there’s a better way to do this by not getting duplicates through your SQL query, but you could hash your unique values to ensure duplicates are removed.

    $tmp = array();
    foreach($array as $r) {
        $tmp[ $r["STATE"] ][ $r["COUNTY"] ][ $r["NEIGHBORHOOD"] ] = NULL;
    }
    

    That should leave you with an array like this:

      [1] => {
               [101] => {
                          [111111] => NULL
                          [333333] => NULL
                          [......] => NULL
                          [xxxxxx] => NULL
                        }
               [201] => {
                          [111111] => NULL
                        }
             }
      [2] => {
               [201] => {
                          [222222] => NULL
                        }
             }
    

    With this structure in mind, you an encapsulate this into a class to return things like all the neighborhoods for a given state or county.

    class myClass{
        protected $_data;
    
        public function __construct($array) 
        {
            $tmp = array();
            foreach($array as $r) {
                $tmp[ $r["STATE"] ][ $r["COUNTY"] ][ $r["NEIGHBORHOOD"] ] = NULL;
            }
           $this->_data = $tmp;
        }
    
        public function getNeighborhoods($state, $county) {
            return array_keys($this->_data[$state][$county]);
        }
    }
    

    At least, the concept is there. The idea is that hashing it like this will remove duplicates as they just end up overwriting each other and it’s nested in a hierarchy, which is sort of how it naturally occurs.

    EDIT

    I quickly threw a test class together and I updated my code with that class. Mind you, there’s no validity checking, etc. But it could be a start for you to get what you’re looking for.

    I hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array that looks something like this: ourThing = array( 'id'
I have an multidimensional array that looks like this: Array ( [0] => Array
I have a returned multi dimensional array from my DB, looking something like this
I have a multidimensional array which, when echoed in PHP, looks like this: {
Let's assume I have the following multidimensional array (retrieved from MySQL or a service):
I have an array of results from mysql relational tables. It looks similar to
I have a mysql table that looks like this: id | uid | title
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
I have a data set from mysql in a multidimensional array. I am using
I receive from my MySQL database a multidimensional array Array ( [0] => Array

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.