samedi 21 mars 2020

Order a array by date in Laravel

I want to order an array with customer comments by the field date. From the most current date to the oldest.

$testimonials = array:356 [▼
0 => array:4 [▼
    "comment" => "blahblahblahblahblah"
    "name" => "John"
    "date" => "12/04/2019"
]
1 => array:4 [▼
  "comment" => "blah blah blah blah blah"
  "name" => "Franky V"
  "date" => "13/05/2019"
]
2 => array:4 [▼
  "comment" => "lololololol"
  "name" => "Peter"
  "date" => "06/03/2020"
]
3 => array:4 [▼
  "comment" => "blahblahblahblahblahblahblahblahblah"
  "name" => "Hugo"
  "date" => "24/01/2019"
]
....

I want to get this result:

$testimonials = array:356 [▼
  0 => array:4 [▼
    "comment" => "lololololol"
    "name" => "Peter"
    "date" => "06/03/2020"
  ]
  1 => array:4 [▼
    "comment" => "blah blah blah blah blah"
    "name" => "Franky V"
    "date" => "13/05/2019"
  ]
  2 => array:4 [▼
    "comment" => "blahblahblahblahblah"
    "name" => "John"
    "date" => "12/04/2019"
  ]
  3 => array:4 [▼
    "comment" => "blahblahblahblahblahblahblahblahblah"
    "name" => "Hugo"
    "date" => "24/01/2019"
  ]

How can I do this within my Laravel controller or with PHP?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33zYF9y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire