Jump to content

Possible to sort Array by sublevel value?


DssTrainer

Recommended Posts

Its an odd question, i think.. but here is the situation:

 

I have an array of data that I pull from the database. I have to extract it using a different method than sort_order, but after I get it, I want to sort it by sort order

$category_data[] = array(
                            'name'  => $result['name'],
                            'href'    => $url->href('category', false, array('path' => $result['path'])),
                            'class'   => $class,
                            'xsort'   => $result['sort_order']
                        );

 

This results in

$category_data

: array =

  0: array =

    name: string = "Electronics"

    href: string = "http://localhost/category/path/1"

    class: string = "cat_lvl_0"

    xsort: string = "1"

  1: array =

    name: string = "CellPhones"

    href: string = "http://localhost/category/path/22"

    class: string = "cat_lvl_0"

    xsort: string = "0"

 

Now, I want to sort it by the "xsort" value. As you can see Electronics has a sort of 1 but CellPhones has a sort of 0. So I want Cellphones first.

 

How can I sort that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.