2016-04-14 2 views
-5

Я хочу сортировать время даты в массиве строк, используя php. Моя строка выглядит так, я хочу сортировать первое время и дату. Напр. 14_04_2016 (дата) и 01_00pm_03_00pm (время будет первым и вторым 15_04_2016 ...), как это ..Как сортировать дату в строковом массиве php

Любое тело есть идея, пожалуйста, предложить мне ..

Заранее спасибо.

Строка Массив:
[0] => 05_00pm_07_00pm | 15_04_2016
[1] => 03_00pm_05_00pm | 15_04_2016
[2] => 07_00pm_09_00pm | 15_04_2016
[3] => 03_00pm_05_00pm | 14_04_2016
[ 4] => 01_00pm_03_00pm | 14_04_2016
[5] => 01_00pm_03_00pm | 15_04_2016
[6] => 01_00pm_03_00pm | 15_04_2016
[7] => 01_00pm_03_00pm | 15_04_2016
[8] => 01_00pm_03_00pm | 15_04_2016
[9] => 01_00pm_03_00pm | 15_04_2016
[10] => 01_00pm_03_00pm | 15_04_2016
[11] => 01_00pm_03_00pm | 15_04_2016
[12] => 01_00pm_03_00pm | 15_04_2016
[13] => 07_00pm_09_00pm | 14_04_2016
[14] => 07_00pm_09_00pm | 16_04_2016
[15] => 01_00pm_03_00pm | 14_04_2016
[16] => 07_00pm_09_00pm | 13_04_2016

+0

Пожалуйста, попробуйте ур. @Naeem Sabasara – RJParikh

+0

@ Ruchish, я делаю взорваться как значения, так и попытки с несколькими сортировками. –

+0

да правильно. @Naeem Sabasara – RJParikh

ответ

1

Попробуйте это будет работать для вас.

$array= Array(
    0 => '05_00pm_07_00pm|15_04_2016',1 => '03_00pm_05_00pm|15_04_2016',2 => '07_00pm_09_00pm|15_04_2016',3 => '03_00pm_05_00pm|14_04_2016', 
    4 => '01_00pm_03_00pm|14_04_2016',5 => '01_00pm_03_00pm|15_04_2016',6 => '01_00pm_03_00pm|15_04_2016',7 => '01_00pm_03_00pm|15_04_2016', 
    8 => '01_00pm_03_00pm|15_04_2016',9 => '01_00pm_03_00pm|15_04_2016',10 => '01_00pm_03_00pm|15_04_2016',11 => '01_00pm_03_00pm|15_04_2016', 
    12 => '01_00pm_03_00pm|15_04_2016',13 => '07_00pm_09_00pm|14_04_2016',14 => '07_00pm_09_00pm|16_04_2016',15 => '01_00pm_03_00pm|14_04_2016', 
    16 => '07_00pm_09_00pm|13_04_2016' 
); 
foreach($array as $key=>$row) 
{ 
    $newArr[$key] = explode("|", $row); 
    $timeArray[] = $newArr[$key][0]; 
    $dateArray[] = $newArr[$key][1]; 
} 

array_multisort($dateArray, SORT_ASC, $timeArray, SORT_ASC, $newArr); 

$finalArray = array(); 
foreach($newArr as $key1=>$row1) 
{ 
    $finalArray[] = implode("|",$row1); 
} 
echo "<pre>"; 
print_r($finalArray); 

Выход

Array 
(
    [0] => 07_00pm_09_00pm|13_04_2016 
    [1] => 01_00pm_03_00pm|14_04_2016 
    [2] => 01_00pm_03_00pm|14_04_2016 
    [3] => 03_00pm_05_00pm|14_04_2016 
    [4] => 07_00pm_09_00pm|14_04_2016 
    [5] => 01_00pm_03_00pm|15_04_2016 
    [6] => 01_00pm_03_00pm|15_04_2016 
    [7] => 01_00pm_03_00pm|15_04_2016 
    [8] => 01_00pm_03_00pm|15_04_2016 
    [9] => 01_00pm_03_00pm|15_04_2016 
    [10] => 01_00pm_03_00pm|15_04_2016 
    [11] => 01_00pm_03_00pm|15_04_2016 
    [12] => 01_00pm_03_00pm|15_04_2016 
    [13] => 03_00pm_05_00pm|15_04_2016 
    [14] => 05_00pm_07_00pm|15_04_2016 
    [15] => 07_00pm_09_00pm|15_04_2016 
    [16] => 07_00pm_09_00pm|16_04_2016 
) 

Также проверьте в интернет-редакторе. Click Here

+1

Да, это здорово .. У меня хорошие результаты. Моя ошибка в том, что я не впал в значение, я делаю прямую выборку значения ...
Спасибо большое !!!!! –

+0

Большое спасибо ... !!!!! –

+0

Добро пожаловать. Рад помочь вам. – RJParikh

Смежные вопросы