“Ordenar la matriz por fecha php” Código de respuesta

Orden por fecha WP PHP

$query = new WP_Query(array(
    'post_status' => 'publish',
    'orderby' => 'publish_date',
    'order' => 'DESC'
  ));
//DESC sorts by newest, ASC by oldest. GL fellow grepper user
Andrew Lautenbach

Orden de matriz de PHP por fecha

usort($array, function($a, $b) {
  return new DateTime($a['datetime']) <=> new DateTime($b['datetime']);
});
Wandering Wolverine

Ordenar la matriz por fecha php

<?php
    function compareDate($date1, $date2){
        return strtotime($date1) - strtotime($date2);
    }
    
    $dateArray = array("2021-11-11", "2021-10-10","2021-08-10", "2021-09-08");
    usort($dateArray, "compareDate");
    
    print_r($dateArray);
?>

//Output

Array
(
   [0] => 2021-08-10
   [1] => 2021-09-08
   [2] => 2021-10-10
   [3] => 2021-11-11
)
Piyush Kamani

Respuestas similares a “Ordenar la matriz por fecha php”

Preguntas similares a “Ordenar la matriz por fecha php”

Más respuestas relacionadas con “Ordenar la matriz por fecha php” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código