I
I
Issue2021-06-25 21:42:06
PHP
Issue, 2021-06-25 21:42:06

How to sort multidimensional array by time in php?

How can I rearrange this array by the time field so that each item element is sorted in ascending order? For clarity:

$arr['date']['type']['item']['time'];

$arr['2021.06.25']['type'][0]['20:45:00'];
$arr['2021.06.25']['type'][1]['06:00:00'];
$arr['2021.06.25']['type'][2]['13:20:00'];

You need to make it look like this:
$arr['2021.06.25']['type'][0]['06:00:00'];
$arr['2021.06.25']['type'][1]['13:20:00'];
$arr['2021.06.25']['type'][2]['20:45:00'];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-06-26
@paulenot

Perhaps so?

sort($arr['2021.06.25']['type']);

print_r($arr);

Here you can execute PHP online
Result:
Array
(
    [2021.06.25] => Array
        (
            [type] => Array
                (
                    [0] => 06:00:00
                    [1] => 13:20:00
                    [2] => 20:45:00
                )

        )

)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question