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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:18:44+00:00 2026-06-06T13:18:44+00:00

I have arrays like this. [11] => Array ( [transactioncurrencyid] => Array ( [!name]

  • 0

I have arrays like this.

[11] => Array
    (
        [transactioncurrencyid] => Array
            (
                [!name] => US Dollar
                [!] => {041E3DC9-D938-DD11-982C-0013724C58B7}
            )

        [smi_processingmonth] => Array
            (
                [!date] => 6/1/2011
                [!time] => 2:27 PM
                [!] => 2011-06-01T14:27:00-07:00
            )

        [smi_cchistoryid] => {678C5036-9EAA-E111-88E0-00155D010302}
        [smi_includeindeal] => Array
            (
                [!name] => No
                [!] => 0
            )

                  [smi_locationid] => Array
            (
                [!name] => 1134 Hooksett Rd
                [!] => {5CC1585B-91AA-E111-88E0-00155D010302}
            )
    )

[12] => Array
    (
        [transactioncurrencyid] => Array
            (
                [!name] => US Dollar
                [!] => {041E3DC9-D938-DD11-982C-0013724C58B7}
            )


        [smi_processingmonth] => Array
            (
                [!date] => 5/1/2011
                [!time] => 2:27 PM
                [!] => 2011-05-01T14:27:00-07:00
            )

        [smi_cchistoryid] => {688C5036-9EAA-E111-88E0-00155D010302}
        [smi_includeindeal] => Array
            (
                [!name] => No
                [!] => 0
            )

        [smi_locationid] => Array
            (
                [!name] => 1134 Hooksett Rd
                [!] => {5CC1585B-91AA-E111-88E0-00155D010302}
            )
    )

How can i group them by location id then by smi_processingmonth

So I get something like this

[1134 Hooksett Rd] => Array
    (
        [ 5/1/2011] = array(
            [transactioncurrencyid] => Array
            (
                [!name] => US Dollar
                [!] => {041E3DC9-D938-DD11-982C-0013724C58B7}
            )


            [smi_processingmonth] => Array
                (
                    [!date] => 5/1/2011
                    [!time] => 2:27 PM
                    [!] => 2011-05-01T14:27:00-07:00
                )

            [smi_cchistoryid] => {688C5036-9EAA-E111-88E0-00155D010302}
            [smi_includeindeal] => Array
                (
                    [!name] => No
                    [!] => 0
                )

            [smi_locationid] => Array
                (
                    [!name] => 1134 Hooksett Rd
                    [!] => {5CC1585B-91AA-E111-88E0-00155D010302}

             )
           )
         [1/1/2011] = array(
          [transactioncurrencyid] => Array
            (
                [!name] => US Dollar
                [!] => {041E3DC9-D938-DD11-982C-0013724C58B7}
            )

        [smi_processingmonth] => Array
            (
                [!date] => 6/1/2011
                [!time] => 2:27 PM
                [!] => 2011-06-01T14:27:00-07:00
            )

        [smi_cchistoryid] => {678C5036-9EAA-E111-88E0-00155D010302}
        [smi_includeindeal] => Array
            (
                [!name] => No
                [!] => 0
            )

                  [smi_locationid] => Array
            (
                [!name] => 1134 Hooksett Rd
                [!] => {5CC1585B-91AA-E111-88E0-00155D010302}
            )
            )
    )

I have tried

   foreach($array as $keys)
                {

                    $key =  $keys['smi_processingmonth']['!date'];;
                    if (!isset($groups[$key])) 
                    {
                        $groups[$key] =  array($keys);
                    } else {
                        $groups[$key][] = $keys;
                    }
                }
                $newGroups = array();

                if(is_array($groups))
                {
                    foreach($groups as $cats => $values)
                    {

                        foreach($values as $itemValues){
                            $st = rtrim(trim($itemValues['smi_locationid']['!']));
                                $key = $st;
                                if (!isset($newGroups[$key])) 
                                {
                                    $newGroups[$key] = array($groups);

                                } else {
                                    $newGroups[$key][] = $itemValues;
                                }
                            }
                        }
                    }

Thanks!

  • 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-06T13:18:46+00:00Added an answer on June 6, 2026 at 1:18 pm

    Taking from Johan with a few modifications:

    • avoid ltrim if already using trim
    • put in a function, I can use temporary variables to maintain readability
    • add a final [], to avoid nasty $name/$date collision, out of original request, but safer
    function compactArray($data)
    {
        $new_structure = array();
        foreach ( $data as $row ) 
          {
            $name = trim($row['smi_locationid']['!name']);
            $date = trim($row['smi_processingmonth']['!date']);
            $new_structure[ $name ][ $date ][] = $row;
        }
        return $new_structure;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two arrays like this first array Array ( [0228] => Array (
I have 3 arrays like this: 1st Array ( [0695] => Array ( [loan_number]
I have an array with multiple sub-arrays like this: Array ( [0] => Array
I have two arrays that are structured like this $array1 = Array ( [0]
i have arrays like this Array( [0] => Array( [member_name] => hohoho [member_type] =>
I currently have two arrays that look like this: Swatches: Array ( [0] =>
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
I have many arrays like this: Array ( [1] => Array ( [Field] =>
I have an array coming in with sub arrays like this Array ( [0]
I have two arrays that both look like this: Array ( [0] => Array

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.