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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:35:00+00:00 2026-06-02T16:35:00+00:00

I have a multi dimentional php array like this : where the column b

  • 0

I have a multi dimentional php array like this :

where the column “b” has 2 possible values ( x, y) and column “v” has 2 possible values ( t,f )

Array
(
[0] => Array
    (
        [a] => 6
        [b] => x
        [c] => t
    )

[1] => Array
    (
        [a] => 4
        [b] => x
        [c] => t
    )
[2] => Array
    (
        [a] => 6
        [b] => y
        [c] => f
    )

I want to rearrange the columns so that they are structured by values , in the following way.

My Question is, is there a smart way to do this using some native php functions , without looping through everything

Array(
    [value of b=x] => Array(
        [value of c=t] => Array( all ids in the array)
        [value of c=f] => Array( all ids in the array)
     )
    [value of b=y] => Array(
        [value of c=t] => Array( all ids in the array)
        [value of c=f] => Array( all ids in the array)
     )

  )         
  • 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-02T16:35:02+00:00Added an answer on June 2, 2026 at 4:35 pm

    I assume that by all ids in the array you mean “all the a column values in the array”. In which case, this is what you want:

    $result = array();
    
    array_walk($array, function($val, $key) use (&$result) {
      $result[$val['b']][$val['c']][] = $val['a'];
    });
    
    print_r($result);
    

    If by ids you mean the outer array indices, simply change $val['a'] to $key in the above code.

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

Sidebar

Related Questions

Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
I have an multi-dimensional array that I want to send to a PHP script
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
If I have a multi dimensional array in PHP like so... [0] => Array
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have a php multidimensional array which looks like this: $fields = array( array('input',
I have a multidimensional array that looks like this [0] => Array ( [recordId]
I have a PHP function which populates a multi-dimensional array $client->getResponse() I want to
I have a multidimensional array in PHP like this: $array = array( Part1 =>
i have a multidimensional array whose index/keys (not the values) are like this: this

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.