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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:28:26+00:00 2026-05-28T04:28:26+00:00

I have a question here. Let’s say I have an array of the form:

  • 0

I have a question here. Let’s say I have an array of the form:

Array
(
     [0] => Array
         (
             [0] => Array
                 (
                     [A] => Array
                         (
                             [id] => 1
                             [firstname] => John
                             [lastname] => Smith
                             [email] => jsmith@gmail.com
                         )

                     [B] => Array
                         (
                         )

                 )

         )

     [1] => Array
         (
             [0] => Array
                 (
                     [A] => Array
                         (
                             [id] => 2
                             [firstname] => Tommy
                             [lastname] => Tom
                             [email] => ttom@gmail.com
                         )

                     [B] => Array
                         (
                         )

                 )

         )

)

How can I replace the index of the outer array by the index of the inner array in order to have an array like this:

Array
(
        [0] => Array
            (
                [A] => Array
                    (
                        [id] => 1
                        [firstname] => John
                        [lastname] => Smith
                        [email] => jsmith@gmail.com
                    )

                [B] => Array
                    (
                    )

            )



        [1] => Array
            (
                [A] => Array
                    (
                        [id] => 2
                        [firstname] => Tommy
                        [lastname] => Tom
                        [email] => ttom@gmail.com
                    )

                [B] => Array
                    (
                    )

            )



)

Thanks in advance!

  • 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-28T04:28:27+00:00Added an answer on May 28, 2026 at 4:28 am

    You have to loop through the arrays and create a new array based on the inner values.

    $in_array = <your array>;
    $out_array = Array();
    
    foreach($in_array as $k => $v) {
        $out_array[$k] = array_shift($v);
    }
    

    Here, $out_array[$k] keeps the original top-level array keys, and array_shift($v) says to dig down one level for the values (taking the value at the first element in the mid-level array using array_shift, and applying it as the value for the new array).

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

Sidebar

Related Questions

I would like to ask some logic question here. Let say I have a
Bit of a beginner question here: Say I have a block of xml: <root>
my first question here.. :) Let's begin with the code... my page is <form
I have theoretical question about OSGi memory management. Let’s say we have some OSGi
I got a simple question here Let's suppose we have a codebase that employs
I have a question here regarding iPhone app submission. I have a free application
C# question here.. I have a UTF-8 string that is being interpreted by a
I have an other active question HERE regarding some hopeless memory issues that possibly
I have a simple unit test case (extensive question here ) on a configuration
The question raised from the question here . In order to have search engines

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.