Skip to content

Sort Multidimensional Array by Alphanumeric value in Magento 2.4.6

For Example, my Array is something like this :

$testArray = [
    "01-01A" => [
        'name' => "test1",
        'test' => "01-01A"
    ],
    "01-06B" => [
        'name' => "test2",
        'test' => "01-06B"
    ],
    "02-05A" => [
        'name' => "test3",
        'test' => "01-05A"
    ],
    "03-33B" => [
        'name' => "test4",
        'test' => "01-33B"
    ],
    "01-044B" => [
        'name' => "test5",
        'test' => "01-044B"
    ],
    "07-098A" => [
        'name' => "test1",
        'test' => "01-098A"
    ],
    "09-0963B" => [
        'name' => "test2",
        'test' => "01-0963B"
    ],
    "10-0596C" => [
        'name' => "test3",
        'test' => "01-0596C"
    ],
    "99-0586C" => [
        'name' => "test4",
        'test' => "01-0586C"
    ],
    "21-984E" => [
        'name' => "test5",
        'test' => "01-984E"
    ]
];

How can I sort this array using a key or ‘test’ ??

Output:

01-01A
01-05A
01-098A
01-06B
01-33B
01-044B
01-0963B
01-0586C
01-0596C
01-984E