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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:24:59+00:00 2026-06-07T05:24:59+00:00

I have a single multidimensional array that I’m trying to merge keys. I’d like

  • 0

I have a single multidimensional array that I’m trying to merge keys. I’d like to merge where identical keys occur on a separate key from the one I’m trying to merge.

My current array looks like so.

Array
(
[0] => Array
    (
        [zone_id] => 2
        [zone_title] => Users
        [link_title] => Users
    )

[1] => Array
    (
        [zone_id] => 2
        [zone_title] => Users
        [link_title] => Add User
    )

[2] => Array
    (
        [zone_id] => 3
        [zone_title] => Locations
        [link_title] => 
    )
)

I would like to leave the array as is with the exception of merging together arrays that have identical zone_id keys.

Result

    Array
(
[0] => Array
    (
        [zone_id] => 2
        [zone_title] => Users
        [link_title] => Array 
                            (
                                [0] => Users
                                [1] => Add user
                            )
    )

[1] => Array
    (
        [zone_id] => 3
        [zone_title] => Locations
        [link_title] => 
    )
)
  • 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-07T05:25:00+00:00Added an answer on June 7, 2026 at 5:25 am
    <?php
    function merge_keys($arr){
        for ($key = 0; $key < count($arr); $key++) {
            $zone_id = $arr[$key]['zone_id'];
            $index = search($arr, $zone_id);
            if ($index != $key && $index != -1){
                $link_title = $arr[$key]['link_title'];
                $link_title2 = $arr[$index]['link_title'];  
                $arr[$key]['zone_id'] = $zone_id;
                $arr[$key]['zone_title'] = $arr[$key]['zone_title'];
                $arr[$key]['link_title'] = array($link_title, $link_title2);
                unset($arr[$index]);
            }
        }
        return $arr;
    }
    
    function search($arr, $zone_id){
        for ($i = count($arr) - 1; $i >= 0 ; $i--) {
            $item = $arr[$i];
            $tmp_zone_id = $item['zone_id'];
            if($tmp_zone_id == $zone_id){
                return $i;
            }
        }
        return -1;
    }
    
    $arr = array(array('zone_id' => 2, 'zone_title' => 'Users', 'link_title' => 'Users'),
                 array('zone_id' => 2, 'zone_title' => 'Users', 'link_title' => 'Add User'),
                 array('zone_id' => 3, 'zone_title' => 'Locations', 'link_title' => ''));
    
    echo "Before change: \n";
    print_r($arr);
    $arr = merge_keys($arr);
    echo "After change: \n\n";
    print_r($arr);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array that look like this: Array [1] => Array (
I am trying to create a single array that contains all of the values
Possible Duplicate: Convert multidimensional array into single array I have this array: Array (
I have a multidimensional array of latitudes and longitudes, and one other single marker
I have a multidimensional associative array, and I want to apply array_walk_recursive so that
I like to convert a single array into a multidimensional array. This is what
I have just noticed that a multidimensional array in C# does not implement IEnumerable<T>
I have a messy tree multidimensional array that I want to do the following
I have a collection of keys in this massive flat single array I would
I have a function that updates fine with a single dimensional array, but with

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.