Jump to content

djkilgus

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

djkilgus's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. kicken, Thank you for the constructive reply. Thanks to you I figured it out. For anyone who is interested here is the correct (single) sort function: function sortByDateThenByPrice($x, $y) { if ( $x[1] == $y[1] ) if ( $x[2] == $y[2] ) return 0; else if ( $x[2] < $y[2] ) return -1; else return 1; else if ( $x[1] < $y[1] ) return -1; else return 1; } usort($productArray, 'sortByDateThenByPrice');
  2. PFMaBiSmAd, thanks for the response. The individual sort functions are working fine. If I comment out usort($productArray, 'sortElement1Asc'); and run the code it sorts by price ascending and vice versa with the other usort line. I just can't get a sort by date, sort by price to work.
  3. I have a multidimensional array that I want to sort by "price" then by "date". Here is an example of the array: $productArray = array ( array ("Bus", "1/1/2010", 15.99), array ("Train", "2/1/2010", 14.99), array ("Car", "3/1/2010", 18.00), array ("Plane", "3/1/2010", 15.99), array ("Bike", "3/1/2010", 9.99), array ("Truck", "1/1/2010", 19.99) ); //sort by date function sortElement1Asc($x, $y) { if ( $x[1] == $y[1] ) return 0; else if ( $x[1] < $y[1] ) return -1; else return 1; } //sort by price function sortElement2Asc($x, $y) { if ( strtotime($x[2]) == strtotime($y[2]) ) return 0; else if ( strtotime($x[2]) < strtotime($y[2]) ) return -1; else return 1; } usort($productArray, 'sortElement1Asc'); usort($productArray, 'sortElement2Asc'); Unfortunately this is just sorting by price (or whatever i sort last). Any ideas?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.