Support » Developing with WordPress » array_multisort order by value closest to todays date

  • Is there a way to use array_multisort with a custom order by? I need the results to display in date order with the first date being the date closest to today’s, as you can see from the code below the matchDate field comes through as a string which I later convert to a date value.

      foreach($matchLists as $matchList)
         {
        
           $fixtures[] = $matchList['matchDate'];
    
         }
      
        array_multisort($fixtures, SORT_DESC, $matchLists);
    
        $newlist = array();
    
          foreach($matchLists as $key => $matchitem)
    
        {
           if(array_key_exists('matchDate', $matchitem))
          {   
                 
              $newlist[$matchitem['matchDate']][$key] = ($matchitem);
        
           }
    
         }
           foreach($newlist as $key => $value)
             {
              $fixtureDate = date('D j M Y ga', strtotime($key));
              }
    • This topic was modified 1 week, 5 days ago by  bcworkz. Reason: code fixed - 1st backtick must be in col 0
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.