array_multisort question
Posted: Wed Jun 06, 2007 4:38 pm
Hello,
I was just wondering if there is a way to use array_multisort to sort by two criteria at the same time. What I have is 14 arrays containing tour information. I use array_multisort to sort by hotel rating like this:
Now I need to take the result and sort $totalPrice so for each sorted star rating the price is presented from highest to lowest. What I did initally was copy the resulting multisort by star rating into a 2D array, then split into individual "sub-arrays" with their own ratings, then sort them in a loop. But that turned out very inefficient and didn't work too well.
I think it's possible to specify in array_multisort() additional sorting criteria, and I tried it like this:
So here I am trying sort by star rating and by total price simultaneously. But that doesn't seem to work. Would anybody please suggest the correct use of array_multisort() so I can accomplish my task?
Your help, as always, will be greatly appreciated.
Thank you.
Victor.
I was just wondering if there is a way to use array_multisort to sort by two criteria at the same time. What I have is 14 arrays containing tour information. I use array_multisort to sort by hotel rating like this:
Code: Select all
array_multisort($starRating, $imageUrl, $hotelName, $departureDate, $returnDate, $tripDuration, $packageCode, $tourOperator, $mealPlan, $roomOccupancy, $outputIndex, $sourceCurrency, $supplierLink, $totalPrice);I think it's possible to specify in array_multisort() additional sorting criteria, and I tried it like this:
Code: Select all
array_multisort($starRating, SORT_ASC, $imageUrl, $hotelName, $departureDate, $returnDate, $tripDuration, $packageCode, $tourOperator, $mealPlan, $roomOccupancy, $outputIndex, $taxes, $sourceCurrency, $supplierLink, $totalPrice, SORT_NUMERIC, SORT_ASC);Your help, as always, will be greatly appreciated.
Thank you.
Victor.