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
)
8
  • 1
    How to sort them - what do you mean? Commented May 17, 2016 at 13:18
  • Have you tried usort? Commented May 17, 2016 at 13:20
  • 3 different array ????? Commented May 17, 2016 at 13:20
  • These 3 arrays i get in loop foreah Commented May 17, 2016 at 13:23
  • foreach ($themes as $value) { $meta = $this->themesMeta->getThemeMeta($value); $caption = $value; if($meta) { $caption = $meta['alias'].' (<a href="https://'. $meta['template-subdomain']. '.' .$_SERVER['HTTP_HOST'].'" target="_blank">Preview</a>)'; } $options .= sprintf($optionTemplate, $value, $caption); } Commented May 17, 2016 at 13:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.