i'm trying to sort the children of an array but failing miserably.. Problem is that only the children should get sorted/compared against another by their ['date']['form_date '] value, not the first layer of the array :(
Array
(
[0] => Array
(
[0] => Array
(
[date] => Array
(
[from_date] => 2018-07-07
[to_date] => 2018-07-07
)
[post] => Special: Pferdefotografie
)
[1] => Array
(
[date] => Array
(
[from_date] => 2018-07-21
[to_date] => 2018-07-21
)
[post] => Fotoexkursion Südafrika
)
[2] => Array
(
[date] => Array
(
[from_date] => 2018-07-21
[to_date] => 2018-07-21
)
[post] => Fotoexkursion Landschaftsfotografie
)
[3] => Array
(
[date] => Array
(
[from_date] => 2018-07-21
[to_date] => 2018-07-21
)
[post] => Bildaufbau und Komposition
)
[4] => Array
(
[date] => Array
(
[from_date] => 2018-07-22
[to_date] => 2018-07-22
)
[post] => Bildaufbau und Komposition
)
)
[1] => Array
(
[0] => Array
(
[date] => Array
(
[from_date] => 2018-08-11
[to_date] => 2018-08-11
)
[post] => Bildaufbau und Komposition
)
[1] => Array
(
[date] => Array
(
[from_date] => 2018-08-04
[to_date] => 2018-08-04
)
[post] => Makrofotografie 1
)
[2] => Array
(
[date] => Array
(
[from_date] => 2018-08-26
[to_date] => 2018-08-26
)
[post] => Tierfotografie 2
)
[3] => Array
(
[date] => Array
(
[from_date] => 2018-08-19
[to_date] => 2018-08-19
)
[post] => Tierfotografie 1
)
)
[2] => Array
(
[0] => Array
(
[date] => Array
(
[from_date] => 2018-09-15
[to_date] => 2018-09-15
)
[post] => Bildaufbau und Komposition
)
[1] => Array
(
[date] => Array
(
[from_date] => 2018-09-02
[to_date] => 2018-09-02
)
[post] => Makrofotografie 2
)
[2] => Array
(
[date] => Array
(
[from_date] => 2018-09-01
[to_date] => 2018-09-01
)
[post] => Makrofotografie 1
)
)
)
I tried on using usort for comparing the dates, but i guess it fails because of the level of nesting!?
usort($events, function ($a, $b) {
return strtotime($a[0]['date']['from_date']) - strtotime($b[0]['date']['from_date']);
});
Any help is much appreciated! Thanks in advance for looking into this :)