I have an array of Towns that have no sorting whatsoever. I would like to sort by the [category][3] which is the province and then the [category][0] which is the region and display each Grouped Province with its regions and then towns underneath it. So the following array:
Array
(
    [0] => Array
        (
            [name] => Name One
            [id] => 1
            [link] => http://mylink1.com
            [category] => Array
                (
                    [0] => Region 1
                    [1] => Town 7
                    [2] => Country
                    [3] => Province 2
                )    
        )
    [1] => Array
        (
            [name] => Name Two
            [id] => 2
            [link] => http://mylink2.com
            [category] => Array
                (
                    [0] => Region 1
                    [1] => Town
                    [2] => Country
                    [3] => Province 3
                )    
        )
    [2] => Array
        (
            [[name] => Name Three
            [id] => 3
            [link] => http://mylink3.com
            [category] => Array
                (
                    [0] => Region 1
                    [1] => Town 5
                    [2] => Country
                    [3] => Province 2
                )
        )
    [6] => Array
        (
            [name] => Name Four
            [id] => 4
            [link] => http://mylink4.com
            [category] => Array
                (
                    [0] => Region 1
                    [1] => Town 1
                    [2] => Country
                    [3] => Province 1
                )
        )
)
... should end up looking like this:
Country (all the same)
Province 1
- Region 1
- - Town 1 name, id, link
Province 2
- Region 1
- - Town 5 name, id, link
- - Town 7 name, id, link
Province 3
- Region 1
- - Town 1 name, id, link
Province is the Primary Grouping factor, then sorted by Region, the Towns in no particular order but I guess Alphabetically would make sense.
I have managed to sort the array by Category using this reference: Sort Multi-dimensional Array by Value but cannot fathom how to sort any further without referencing the Province specifically in a loop by using its name. i.e.
/// shortened version..
foreach($array as $key=>$value)...
   if($value == "Province 1") : do something here with these matches
     ... etc
Any help would be appreciated.
 
     
     
    