array(29) {
["03.2020"]=>
array(4) {
["likes"]=>
int(46003)
["comments"]=>
int(2663)
["reposts"]=>
int(2939)
["views"]=>
int(3386015)
}
["01.2020"]=>
array(4) {
["likes"]=>
int(8958)
["comments"]=>
int(612)
["reposts"]=>
int(404)
["views"]=>
int(699785)
}
["02.2020"]=>
array(4) {
["likes"]=>
int(63776)
["comments"]=>
int(3298)
["reposts"]=>
int(3218)
["views"]=>
int(4411204)
}
["01.2019"]=>
array(4) {
["likes"]=>
int(33402)
["comments"]=>
int(2037)
["reposts"]=>
int(1096)
["views"]=>
int(1236658)
}
["12.2019"]=>
array(4) {
["likes"]=>
int(47592)
["comments"]=>
int(1846)
["reposts"]=>
int(832)
["views"]=>
int(1552732)
}
}
$array = [
'23.2001',
'23.2000',
'01.2005',
'05.2020',
'01.2020',
'30.1998',
'03.2020',
'09.2020',
'04.1998',
'20.2005',
];
function camp($a, $b)
{
$a = explode('.', $a);
$b = explode('.', $b);
if ($a[1] == $b[1])
{
if ($a[0] < $b[0])
{
return -1;
} elseif($a[0] > $b[0])
{
return 1;
} elseif ($a[0] == $b[0]) {return 0;}
}
elseif ($a[1] < $b[1])
{
return -1;
} elseif($a[1] > $b[1])
{
return 1;
}
}
usort($array, 'camp');
foreach($array as $v)
{
echo $v . '<br>';
}
$array = [
'03.2001' => [],
'01.2000' => [],
'01.2005' => [],
'05.2020' => [],
'01.2020' => [],
'30.1998' => [],
'03.2020' => [],
'09.2020' => [],
'04.1998' => [],
'11.2005' => [],
];
uksort($array, function(string $a, string $b): int {
return date_create_from_format('m.Y', $a) <=> date_create_from_format('m.Y', $b);
});