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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:21:26+00:00 2026-06-11T09:21:26+00:00

I got the following array , as a result from the MySQL query: Array

  • 0

I got the following array , as a result from the MySQL query:

Array
(
    [0] => Array
        (
            [id] => 11
            [owner] => Mark
        )

    [1] => Array
        (
            [id] => 10
            [owner] => David
        )

    [2] => Array
        (
            [id] => 9
            [owner] => Poul
        )

    [3] => Array
        (
            [id] => 8
            [owner] => Peter
        )

    [4] => Array
        (
            [id] => 7
            [owner] => Peter
        )

    [5] => Array
        (
            [id] => 6
            [owner] => Lucas
        )

)

Is there a way to modify it, using the PHP functions and ommit the foreach process?

I would like it to look following:

Array
(
    11 => Mark
    10 => David
    9 => Poul
    8 => Peter
    7 => Peter
    6 => Lucas
)

So , basicly it should build this array from the id and the owner values. Like id => owner.

Is that possible?

  • 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-11T09:21:27+00:00Added an answer on June 11, 2026 at 9:21 am

    If you’re using PDO, you can do something like this:

    $stmt = $dbh->query("SELECT id, owner FROM table");
    $arr = $stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);
    

    This should give you an array, where the indices of the array are the values of the first column in your result, namely id.

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

Sidebar

Related Questions

I've got the following MySQL query: <?php $sql = SELECT * FROM my_table; $result
print_r($array) results I retrieved some values from database and got the following result while
I have produced a result from the following query as shown below.Now the result
Got a relatively simple MySQL query that I'm pulling using php with the following
I got the following array (shortened ... multiple dot mean that they are data
I got following code from net and it looks everything is proper but i'm
I've got following problem: (c#) There is some class (IRC bot), which has method,
I'm trying to create associative array of objects from row result set with member
I've got some problems with the following code in my PHP/MySQL application. It works
I've got the following array $weight and I want to store these values to

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.