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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:24:15+00:00 2026-05-24T20:24:15+00:00

Suppose I have an array such as the one below. If I wanted to

  • 0

Suppose I have an array such as the one below. If I wanted to separate and divide out the array below into multiple arrays containing records with only one tl_id, how would I go about doing this efficiently?

Example: so notice how there are two tl_id’s (there could possibly be more): 275 and 328. I want two separate out that big array into two arrays. array1 would contain all the records that has tl_id’s of 275. And array2 would contain all the records with tl_id 328.

I was thinking of a for loop and separating it out that way, but was hoping there’s some PHP wizardy function I can use to simplify this action.

array(5) {
  [0] => array(14) {
    ["tl_id"] => int(275)
    ["tl_email"] => string(27) "abc@gmail.com"
    ["tl_first_name"] => string(9) "Jane"
    ["tl_last_name"] => string(6) "Doe"
    ["target_id"] => int(354)
    ["target_first_name"] => string(4) "Rudy"
    ["target_last_name"] => string(5) "Smith"
  }
  [1] => array(14) {
    ["tl_id"] => int(275)
    ["tl_email"] => string(27) "abc@gmail.com"
    ["tl_first_name"] => string(9) "Jane"
    ["tl_last_name"] => string(6) "Doe"
    ["target_id"] => int(354)
    ["target_first_name"] => string(4) "Rudy"
    ["target_last_name"] => string(5) "Smith"
  }
  [2] => array(14) {
    ["tl_id"] => int(275)
    ["tl_email"] => string(27) "abc@gmail.com"
    ["tl_first_name"] => string(9) "Jane"
    ["tl_last_name"] => string(6) "Doe"
    ["target_id"] => int(194)
    ["target_first_name"] => string(5) "Katie"
    ["target_last_name"] => string(4) "Smith"
  }
  [3] => array(14) {
    ["tl_id"] => int(328)
    ["tl_email"] => string(20) "qrf@hotmail.com"
    ["tl_first_name"] => string(6) "John"
    ["tl_last_name"] => string(9) "Smith"
    ["target_id"] => int(219)
    ["target_first_name"] => string(6) "Kelly"
    ["target_last_name"] => string(5) "Smith"
  }
  [4] => array(14) {
    ["tl_id"] => int(328)
    ["tl_email"] => string(20) "qrf@hotmail.com"
    ["tl_first_name"] => string(6) "John"
    ["tl_last_name"] => string(9) "Smith"
    ["target_id"] => int(213)
    ["target_first_name"] => string(5) "Chris"
    ["target_last_name"] => string(5) "Jones"
  }
}
  • 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-24T20:24:16+00:00Added an answer on May 24, 2026 at 8:24 pm

    I hope this will be of help.

    <?php
    $test = array(
      array(
        "tl_id" => 275,
        "tl_email" => "abc@gmail.com",
        "tl_first_name" => "Jane",
        "tl_last_name" => "Doe",
        "target_id" => 354,
        "target_first_name" => "Rudy",
        "target_last_name" => "Smith",
      ),
      array(
        "tl_id" => 275,
        "tl_email" => "abc@gmail.com",
        "tl_first_name" => "Jane",
        "tl_last_name" => "Doe",
        "target_id" => 354,
        "target_first_name" => "Rudy",
        "target_last_name" => "Smith",
      ),
      array(
        "tl_id" => 278,
        "tl_email" => "abc@gmail.com",
        "tl_first_name" => "Jane",
        "tl_last_name" => "Doe",
        "target_id" => 354,
        "target_first_name" => "Rudy",
        "target_last_name" => "Smith",
      ),
    );
    
    $result = array_reduce($test,
        function($result, $item)
        {
            $result[$item["tl_id"]][] = $item;
            return $result;
        }
    );
    print_r($result);
    

    This function walks the array and builds a new array where the items have been grouped by id.

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

Sidebar

Related Questions

Suppose I have an array of a objects of user defined class. Wanted to
Suppose I have an array such as: var arr = [1, 2, 3]; And
Suppose you have an unsorted array, how will you find 2 equal elements such
I have two files, one containing an array in PHP that is echo ed
Suppose I have an array of values [a,b,c,d,...] and a function f(x,...) which returns
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have an array of nodes (objects). I need to create a duplicate
I recently came across a question somewhere: Suppose you have an array of 1001
Suppose we have a vector/array in C++ and we wish to count which of
Suppose I have a collection (be it an array, generic List, or whatever is

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.