0

How to sort an array in alphabetical order using codeigniter

array(
     Array(

            [id] => 4
            [business_category] => Air_conditioning-Auto
            [business_name] => test business
        );
      Array(

            [id] => 55
            [business_category] => Air_conditioning-Auto
            [business_name] => asdf
        );
);
Ritu
  • 19
  • 4

1 Answers1

0

Answer taken from this post: Sort array of objects by object fields

Use usort, here's an example adapted from the manual:

function cmp($a, $b)
{
    return strcmp($a->name, $b->name);
}

usort($your_data, "cmp");

If you're sorting the array from inside the class and your sorting function cmp is also defined inside the class, then use this:

usort($your_data, array($this, "cmp"))
Community
  • 1
  • 1
Waqas Shahid
  • 1,051
  • 1
  • 7
  • 22