0

I have next array:

Array ( 
[15709] => stdClass Object ( 
  [pid] => 15709 
  [channel_ID] => 51 
  [date] => 2016-03-21 00:30:00 
  [program_info] => Х/ф "Стелла" ) 
[15710] => stdClass Object ( 
  [pid] => 15710 [channel_ID] => 51 
  [date] => 2016-03-21 02:20:00 
  [program_info] => Х/ф "Часы доблести" ) 
[15711] => stdClass Object ( 
  [pid] => 15711 
  [channel_ID] => 51 
  [date] => 2016-03-21 06:15:00 
  [program_info] => Фильм-концерт "Хичкок. Концерт в магазине" 
) )

I need sort him by field [date], should first go to the elements starting from the specified time 05:00:00, result must be somthing like this:

Array ( 
    [15711] => stdClass Object ( 
      [pid] => 15711 
      [channel_ID] => 51 
      [date] => 2016-03-21 06:15:00 
      [program_info] => Фильм-концерт "Хичкок. Концерт в магазине" )
    [15709] => stdClass Object ( 
      [pid] => 15709 
      [channel_ID] => 51 
      [date] => 2016-03-21 00:30:00 
      [program_info] => Х/ф "Стелла")
    [15710] => stdClass Object ( 
      [pid] => 15710 [channel_ID] => 51 
      [date] => 2016-03-21 02:20:00 
      [program_info] => Х/ф "Часы доблести"
    ) )
9
  • 2
    actually first array is sorted by date, second one is not. or I miss something? Commented Mar 25, 2016 at 13:42
  • 2
    stackoverflow.com/questions/17439905/php-array-multisort look this question. you question is dublicated. Commented Mar 25, 2016 at 13:43
  • 1
    your question doesnt make sense. your expected result is not sorted by date. Commented Mar 25, 2016 at 13:50
  • 1
    result must sort by custom date time Commented Mar 25, 2016 at 13:52
  • 1
    @CodeGodie, I need sort from 05:00 to 04:59, somthing like this: array('05:00','06:00','07:00','12:00','14:00','16:00','22:00','23:00','02:00','04:00') Commented Mar 25, 2016 at 13:57

1 Answer 1

1

Try something like this:

uasort($myarray, function($a, $b) {
    if ($a['date'] == $b['date']) {
        return 0;
    }
    return ($a['date'] < $b['date']) ? -1 : 1;
})
Sign up to request clarification or add additional context in comments.

2 Comments

I need sort from 05:00 to 04:59, somthing like this: array('05:00','06:00','07:00','12:00','14:00','16:00','22:00','23:00','02:00','04:00')
You can explode the date in the function and compare the time only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.