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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:51:12+00:00 2026-05-13T14:51:12+00:00

In the multidimensional array below, I would like to merge arrays that have the

  • 0

In the multidimensional array below, I would like to merge arrays that have the same merge_id. I’m not sure “merge” is the right word: in the example below, array[‘0’] should become array[‘0’] with in it array[‘0’][‘0’] and array[‘0’][‘1’], the latter being equal to array[‘1’]. I hope this makes sense …

The array comes out of the db sorted on merge_id so arrays with matching merge_id are always “next to” each other, and there will only ever be 2 with the same merge_id

As I loop through the array I know I need to keep a variable that is always equal to the previous merge_id and if there is a match between previous and current, then merge.

Array
(
    [0] => Array
        (
            [client_id] => 5
            [company_name] => company111_name
            [id] => 3
            [fee] => 111
            [year] => 2009
            [quarter] => 3
            [date_inserted] => 1264948583
            [description] => 2009 - Q3


            [fee_type] => 
            [merge_id] => a87ff679a2f3e71d9181a67b7542122c
            [total_paid] => 0
            [total_remainder] => 0
        )

    [1] => Array
        (
            [client_id] => 5
            [company_name] => company111_name
            [id] => 6
            [fee] => 55.5
            [year] => 2010
            [quarter] => 2
            [date_inserted] => 1264949470
            [description] => 2010 - Q2


            [fee_type] => 
            [merge_id] => a87ff679a2f3e71d9181a67b7542122c
            [total_paid] => 0
            [total_remainder] => 0
        )

    [2] => Array
        (
            [client_id] => 5
            [company_name] => company111_name
            [id] => 4
            [fee] => 111
            [year] => 2009
            [quarter] => 4
            [date_inserted] => 1264948583
            [description] => 2009 - Q4


            [fee_type] => 
            [merge_id] => 
            [total_paid] => 0
            [total_remainder] => 0
        )



    [3] => Array
        (
            [client_id] => 5
            [company_name] => company111_name
            [id] => 7
            [fee] => 55.5
            [year] => 2010
            [quarter] => 3
            [date_inserted] => 1264949470
            [description] => 2010 - Q3


            [fee_type] => 
            [merge_id] => 
            [total_paid] => 0
            [total_remainder] => 0
        )

)

Code

$merger = $data['search']['0']['merge_id'];
            $i = 0;
            foreach($data['search'] as $fee)
            {
                if($fee['merge_id'] == $merger)
                {
                    //bump up & merge arrays
                    ???
                }           

                $merger = $fee['merge_id'];
                $i++;
            }
  • 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-13T14:51:12+00:00Added an answer on May 13, 2026 at 2:51 pm

    You can use the ID as key to put all items with the same ID in the same array:

    $merged = array();
    foreach ($data['search'] as $fee) {
        if ($fee['merge_id'] == '') {
            continue;
        }
        if (!isset($merged[$fee['merge_id']])) {
            $merged[$fee['merge_id']] = array();
        }
        $merged[$fee['merge_id']][] = $fee;
    }
    $merged = array_values($merged);
    

    Notice that this will skip the items with an empty merge ID. You could also use a default merge ID in that case by replacing continue; with $fee['merge_id'] = 0;.

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

Sidebar

Related Questions

I have very long multidimensional array that have many sub arrays. I would like
I have a large multidimensional array that I would like to store into a
I have a multidimensional array of arrays (source below), where my keys and values
I have an multidimensional array that looks like this: Array ( [0] => Array
I have a large multidimensional array structured like the sample below. [ ['name' =>
I have a function which sorts data in a multidimensional array, as shown below:
So I have a multidimensional array, containing 36 arrays. I want for a page
I have a multidimensional array. The code below outputs one entire column. <?php for
For example, I have multidimensional array as below: $array = array ( 0 =>
i have multi dimensional array like below, Array ( [14289] => Array ( [0]

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.