0

I have three arrays. How do I sort them by key order

    Array
(
    [network-id] => 4
    [network-subdomain] => n3
    [source-id] => 89
    [about-page-id] => 5613
    [contacts-page-id] => 2605
    [logo-provider] => option-tree
    [alias] => Template 3
    [template-subdomain] => template3
    [order] => 3
)
Array
(
    [network-id] => 2
    [network-subdomain] => n1
    [source-id] => 87
    [about-page-id] => 2
    [contacts-page-id] => 2754
    [logo-provider] => redux
    [alias] => Template 1
    [template-subdomain] => template1
    [order] => 1
)
Array
(
    [network-id] => 3
    [network-subdomain] => n2
    [source-id] => 88
    [about-page-id] => 2
    [contacts-page-id] => 26
    [logo-provider] => option-tree
    [alias] => Template 2
    [template-subdomain] => template2
    [order] => 2
)
Martin
  • 22,212
  • 11
  • 70
  • 132

1 Answers1

1

You can sort by using usort

function compare_order($a, $b)
{
    return strnatcmp($a['order'], $b['order']);
}

// sort alphabetically by order
 usort($a, 'compare_order');

you can see demo

KARTHI SRV
  • 499
  • 4
  • 20