Array Sorting!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wiseone
Forum Newbie
Posts: 1
Joined: Tue Feb 27, 2007 1:00 am

Array Sorting!

Post by wiseone »

i got 4 divs in one page which holds contain in them... by default i hav set the sort order to win-xp, win-vista, mac-os-x & linux... i m allowing user to customize the way they want the order to be.. via scriptaculous (Sortable.create) function, when the user is done with the sort order, the script simply save the info in cookie, so next time when the user visits the website my script looks in the cookie for sort order n if its present then my default sort order is reset by user's sort-order.... n the page is rendered!

array #1 info comes from mysql database.. array #2 from users cookie i use explode("," , $sortorder) to store it in array #2...

Is there ne other way by which it can be achieved????? do i need to store the id and sortorder in the cookie or only sortorder will do??? i m really confused! n stuck for last 2 days...

thnx for your help!

Code: Select all

Array #1 (
  [0] => Array (
    [sortorder] => 1
    [id] => 3
    [name] => Windows XP
  )

  [1] => Array (
    [sortorder] => 2
    [id] => 4
    [name] => Windows Vista
  )

  [2] => Array (
    [sortorder] => 3
    [id] => 2
    [name] => Mac OSX
  )

  [3] => Array (
    [sortorder] => 4
    [id] => 1
    [name] => Linux
  )
)

Array #2 (
  [0] => Array (
    [sortorder] => 2
  )

  [1] => Array (
    [sortorder] => 1
  )

  [2] => Array (
    [sortorder] => 4
  )

  [3] => Array (
    [sortorder] => 3
  )
)
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

I think this will work. OrderArray is the array you are getting from you cookie, and the unsortedArray is the array you have with the operating systems.

Code: Select all

foreach( $orderArray as $order )
{
  $sortedArray[] = $unsortedArray[$order] ;
}
Post Reply