0

I am trying custom sort categories by description.The description field of each category only has a number in it.

I have tried this but it does not seem to be working

for ($x = 0; $x < count($categories)-1; $x++){
    for ($i = 0; $i < count($categories)-1; $i++){
        if (((int)($categories[i]->category_description))<((int)($categories[i+1]->category_description))) {
            echo("success");
            $temp =$categories[i];
            $categories[i]=$categories[i+1];
            $categories[i+1]=$temp;
        };
    };
};

Any ideas would be greatly appreciated,thanks.

Barry
  • 3,683
  • 1
  • 18
  • 25
Adam Katz
  • 6,999
  • 11
  • 42
  • 74
  • you have array of objects and want sort it by property category_description. If i'm right, use usort. there are many anawers here – splash58 Jun 12 '15 at 11:28
  • I know the usort can work, but I wanted to try do it with a bubble sort as a personal project and I can't work out why that won't work – Adam Katz Jun 12 '15 at 11:36
  • http://stackoverflow.com/questions/9001294/bubble-sort-implementation-in-php – splash58 Jun 12 '15 at 12:03

0 Answers0