Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
¿Cómo ordenar la matriz y tomar solo 5 elementos?

¿Cómo obtener solo los 5 artículos más nuevos de la matriz?

Por ejemplo:

 usort($articles, function ($item1, $item2) { return $item2['created_at'] <=> $item1['created_at']; });

Esto los ordenará de forma descendente y no necesito mostrarlos todos.

Cuál sería la mejor forma de hacer esto? ¿Es posible sin volver a repetir y almacenar en una nueva matriz?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Usar array_slice en la matriz ordenada debería ser suficiente.

 usort($articles, function ($item1, $item2) { return $item2['created_at'] <=> $item1['created_at']; }); $fiveFirst = array_slice($articles, 0, 5);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!