Specific complex array sorting

Posted by TheDeadMedic on Stack Overflow See other posts from Stack Overflow or by TheDeadMedic
Published on 2010-06-08T01:29:01Z Indexed on 2010/06/08 1:32 UTC
Read the original article Hit count: 374

Okay, a before;

Array (
    'home' => array('order' => 1),
    'about' => array(),
    'folio' => array('order' => 2),
    'folio/web' => array('order' => 2),
    'folio/print' => array('order' => 1)
    'contact' => array('order' => 2)
)

And a desired after;

Array (
    'home' => array('order' => 1),
    'contact' => array('order' => 2),
    'folio' => array('order' => 2),
    'folio/print' => array('order' => 1),
    'folio/web' => array('order' => 2),
    'about' => array()
)

I know, horrific (don't ask!)

See how the slash in the key indicates children, and how the order is nested accordingly? And items without orders are simply shifted to the bottom.

But also how multiple 'same level' items with the same order are merely sorted by key?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays