php,如何排序三个数组

时间:2016-05-17 13:13:22

标签: php arrays

我有三个阵列。如何按键顺序对它们进行排序

    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
)

1 个答案:

答案 0 :(得分:1)

您可以使用usort

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

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

您可以看到demo