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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:10:47+00:00 2026-05-30T02:10:47+00:00

I have a small tricky question with nested arrays. I am getting something like

  • 0

I have a small tricky question with nested arrays. I am getting something like that from my database:

array
  0 => 
    array
      'id' => string '81' (length=2)
      'value' => string 'foobar' (length=6)
      'created_at' => string '2012-02-18 22:09:57' (length=19)
      'updated_at' => string '2012-02-18 22:09:57' (length=19)
  1 => 
    array
      'id' => string '106' (length=3)
      'value' => string 'barfoo' (length=6)
      'created_at' => string '2012-02-19 15:11:47' (length=19)
      'updated_at' => string '2012-02-19 15:11:48' (length=19)

What I want to achieve now is to extract a simple associative array, where one “column” becomes the key and one “column” becomes the value. For the case id / value, the result should then look like that:

array
  81 => 'foobar'
  106 => 'barfoo'

I know that I could do nested loops to foreach through all of the arrays, but I was wondering if there is a quicker and more native method. I was playing around with array_intersect, but it does not seem to deliver what I need.

  • 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-30T02:10:48+00:00Added an answer on May 30, 2026 at 2:10 am

    Well, this one doesn’t involve nested loops:

    $result = array();
    
    foreach($queryResult as $row) {
        $result[$row['id']] = $row['value'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JS function that does Ajax for me and another like
That's tricky. I have a small button over a very big one. When the
I have small utility that does some processing on a file and changes the
I have small database of business and their addresses. Using the Google Geocode API
I have small web app that generate PDF files as a report. I'm trying
I've a question for you. We have built a software that has a single
I have a small command line tool and after running it, I'd like to
I have a small webshop-like web application, and i have big plans :-) I
I have a numerous small pieces of data that I want to be able
I’ve been working on a few small scale Access projects that have turned large

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.