• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change order of foreach loop?

#6
[eluser]Phil Sturgeon[/eluser]
They both work fine for now.

If this is a one-off and you dont want to modify the model, you can use ksort.

Create an array of your users with their join date as the key like so:

Code:
foreach($this->users_m->getUsers() as $user) {
    $users[$user->join_date.$user->name] = $user;
}
ksort($users);

That's obviously less efficient than ordering in the DB, but still works. Useful way to do it sometimes Smile


Messages In This Thread
Change order of foreach loop? - by El Forum - 09-25-2008, 07:47 PM
Change order of foreach loop? - by El Forum - 09-25-2008, 08:09 PM
Change order of foreach loop? - by El Forum - 09-25-2008, 09:47 PM
Change order of foreach loop? - by El Forum - 09-25-2008, 10:11 PM
Change order of foreach loop? - by El Forum - 09-25-2008, 10:13 PM
Change order of foreach loop? - by El Forum - 09-26-2008, 07:49 AM
Change order of foreach loop? - by El Forum - 09-26-2008, 08:25 AM
Change order of foreach loop? - by El Forum - 09-26-2008, 06:17 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.