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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:47:32+00:00 2026-05-23T23:47:32+00:00

I have two arrays: $a = array( array(id => 132), array(id => 131), array(id

  • 0

I have two arrays:

$a = array(
    array("id" => 132),
    array("id" => 131),
    array("id" => 129),
    array("id" => 128)
)

$b = array(
    array("id" => 129, "attachment_id" => 111),
    array("id" => 129, "attachment_id" => 112),
    array("id" => 132, "attachment_id" => 113),
    array("id" => 132, "attachment_id" => 114),
    array("id" => 132, "attachment_id" => 115)
)

I need to make one array from those two. id key must be unique so it can’t be repeated. Problem is that: I need to make new element in that new array called attachments that’s array and contains values of attachment_id for that id. You see, there may be more that one attachment_id for id.

Its hard to explain, but I hope that you’ll understand! Thanks in advice.

Edit:

Here is desired outcome:

$c = array(
    array("id" => 132, 'attachments' => array(113, 114, 115)),
    array("id" => 131, 'attachments' => array()),
    array("id" => 129, 'attachments' => array(111, 112)),
    array("id" => 128, 'attachments' => 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-05-23T23:47:32+00:00Added an answer on May 23, 2026 at 11:47 pm

    Something like:

    $a = array(
        array("id" => 132),
        array("id" => 131),
        array("id" => 129),
        array("id" => 128)
    );
    
    $b = array(
        array("id" => 129, "attachment_id" => 111),
        array("id" => 129, "attachment_id" => 112),
        array("id" => 132, "attachment_id" => 113),
        array("id" => 132, "attachment_id" => 114),
        array("id" => 132, "attachment_id" => 115)
    );
    
    $c = array();
    
    foreach ($a as $idEntry) {
        $tmp = array(
            'id' => $idEntry['id'],
            'attachments' => array()
        );
    
        foreach ($b as $bIdx => $attachmentEntry) {
            if ($attachmentEntry['id'] == $idEntry['id']) {
                $tmp['attachments'][] = $attachmentEntry['attachment_id'];
                unset($b[$bIdx]);
            }
        }
    
        $c[] = $tmp;
    }
    
    print_r($c);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] =>
Consider I have two arrays: $friends = Array('foo', 'bar', 'alpha'); $attendees = Array('foo', 'bar');
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays: Array ( [0] => 2 [1] => 3 ) and
I have two arrays each array has some values for instance: int a[] =
I have two arrays $data1 = array() $data1 = array( '10','22','30') and also another
I have this two arrays: $arr1=array( array(id => 8, name => test1), array(id =>
I have two arrays: 1) The first array: array( [0] => array( [code] =>
I have two arrays in php $arrNum = array(1.7, 1.52, 0.01, 0.11); $arrStr =

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.