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

  • Home
  • SEARCH
  • 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 6151433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:46:06+00:00 2026-05-23T19:46:06+00:00

I have an array similar to this Array ( [0] => Array ( [showname]

  • 0

I have an array similar to this

Array
(
    [0] => Array
        (
            [showname] => White Collar
            [air_time] => 1310590800
        )

    [1] => Array
        (
            [showname] => Chopped
            [air_time] => 1310590800
        )

    [2] => Array
        (
            [showname] => Covert Affairs
            [air_time] => 1310587200
        )
    } ... etc

I want to crete a new array that is sorted by air_time. for example all shows containing the same air_time should be in [0] then [1] then [2] etc..

An example of the output i would like is this:

Array
(
    [0] => Array
        (
            [time] => 1310590800
            [shows] => Array
                (
                    [name] => White Collar
                    [name] => Chopped
                )

        )

    [1] => Array
        (
            [time] => 1310587200
            [shows] => Array
                (
                    [name] => Covert Affairs
                )

        )
}

I’ve been looking at different array methods like multisort but i wasn’t able to figure it out.

Could you point me in the right direction? thanks

update i know how to sort the array normally by time, i just dont know how can i separate and group elements that have the same time

  • 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-23T19:46:07+00:00Added an answer on May 23, 2026 at 7:46 pm

    It’s not that hard if you wrap your head around it. By the way, you can’t have multiple array elements with the same key name.

    $shows = array(
        array(
            'showname' => 'White Collar',
            'air_time' => 1310590800
        ),
        array(
            'showname' => 'Covert Affairs',
            'air_time' => 1310587200
        ),
        array(
            'showname' => 'Chopped',
            'air_time' => 1310590800
        )
    );
    
    /* Sort by air_time (descending) */
    usort($shows, function ($a, $b) {
        return ($b['air_time'] - $a['air_time']);
    });
    
    
    /* Regroup array (utilizing the fact that the array is ordered) */
    $regrouped = array();
    $c = 0;
    foreach ($shows as $show) {
        if ($c > 0 && $regrouped[$c - 1]['time'] === $show['air_time']) {
            $regrouped[$c - 1]['shows'][] = $show['showname'];
        } else {
            $regrouped[] = array('time'  => $show['air_time'],
                                 'shows' => array($show['showname']));
            $c++;
        }
    }
    
    print_r($regrouped);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code similar to this filtering entries in an Array of Objects: var
Suppose I have an array similar to this (actual values probably will not be
I have a byte array similar to this (16 bytes): 71 77 65 72
I have an array that looks similar to this, [4] => Common_Model Object (
I have a multi-dimensional array similar to the example below that I want to
I have this array similar to this: $suppliers = array( 'Utility Warehouse' => array('Gas'
Shortly i have string variable similar to this:(every li elements is array element.) <li>first</li>
I have an array of hashes, and I want the unique values out of
I have an array similar to {A,B,C,D,E,F,G,H}. I would like to be able to
I have an array that looks 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.