Check out our brand new Local Poker Communities! Get updates and interact with poker players in your area.
Visit the United States Poker Community | Visit the California Poker Community | Read more about the Launch of P5s Local
  1. Hi, I have some arrays, i think the term may be associated arrays or linked arrays, that are linked by index number. For example, I have an array called foodname and an array called foodprice, with foodname[1] corresponding to foodprice[1] and so on. I need to sort these arrays alphabetically by foodname. So when foodname is sorted, the corresponding foodprice value is not lost, it is sorted to the same index position. These values are actually kept as session variables, my session structure is called session.cart, and the arrays are called session.cart.foodname and session.cart.foodprice. I dont know if this changes anything. Can anyone help me with this? Thanks a lot.
  2. OT?
  3. I think you need to combine the arrays, then do a sort. I don't see how to keep the corresponding value without combining them.
     
  4. Does it have to be done like this? It would be better to make a food class with two properties: name and price. Then you don't have to keep track of two different arrays. If you must use two arrays then something like this would work:

    foodname.sort(Array foodprice)
    {
    whenever exchanging values in foodname
    {
    temp = foodname[i];
    foodname[i] = foodname[j];
    foodname[j] = temp;

    temp = foodprice[i];
    foodprice[i] = foodprice[j];
    foodprice[j] = temp;
    }
    }

Similar Threads