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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:21:34+00:00 2026-06-07T22:21:34+00:00

I have simple array array( array( ‘id’=>5, ‘something’ => 2, ‘dsadsa’ => ‘fsfsd )

  • 0

I have simple array

array( 
   array( 'id'=>5, 'something' => 2, 'dsadsa' => 'fsfsd )
   array( 'id'=>20, 'something' => 2, 'dsadsa' => 'fsfsd )
   array( 'id'=>30, 'something' => 2, 'dsadsa' => 'fsfsd )
)

How to create associative array by id field (or something else) from it in the right way?

array( 
   '5' => array(  'something' => 2, 'dsadsa' => 'fsfsd )
   '20' => array(  'something' => 2, 'dsadsa' => 'fsfsd )
   '30' => array(  'something' => 2, 'dsadsa' => 'fsfsd )
)
  • 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-07T22:21:36+00:00Added an answer on June 7, 2026 at 10:21 pm

    @NikitaKuhta, nope. There is no slice function which returns a column of values in a 2D keyed table associated with a given key or column heading. You can use some of the callback array_… functions, but you will still need to execute a custom function per element so its just not worth it. I don’t like Core Xii’s solution as this corrupts the original array as a side effect. I suggest that you don’t use references here:

    $new_array = array();
    foreach ($original_array as $slice) {
        $id = (string) $slice['id'];
        unset($slice['id']);
        $new_array[$id] = $slice;
    }
    # And now you don't need the missing unset( $slice)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple associative array: $ar = array( 1=>'foo', 2=>'bar', 5=>'foobar', 8=>'barfoo' )
I have a simple array of hashes retrieved from Redis in my Ruby on
I have a simple associative array. $a = array(a=>b, c=>d); I want to check
I have a simple array search I'm doing with php. $qs = 'something$'; //
I have an simple array array = [apple, orange, lemon] array2 = [[apple, good
I have a simple array with bank holidays: var bank_holidays = ['06/04/2012','09/04/2012','07/05/2012','04/06/2012','05/06/2012','27/08/2012','25/12/2012','26/12/2012','01/01/2013','29/03/2013','01/04/2013','06/05/2013','27/05/2013']; I want
I have a simple array with x number of items. I am displaying them
I have a simple array of stuff: $array = array(apples,oranges,strawberries); I am trying to
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]
I have a simple simulated array with two elements: bowl["fruit"] = "apple"; bowl["nuts"] =

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.