Ordenar Array Multidimensional PHP


/ Published in: PHP
Save to your folder(s)

Ordena cualquier array multidimensional en base a un campo específico


Copy this code and paste it in your HTML
  1. function orderMultiDimensionalArray ($toOrderArray, $field, $inverse = false) {
  2. $position = array();
  3. $newRow = array();
  4. foreach ($toOrderArray as $key => $row) {
  5. $position[$key] = $row[$field];
  6. $newRow[$key] = $row;
  7. }
  8. if ($inverse) {
  9. arsort($position);
  10. }
  11. else {
  12. asort($position);
  13. }
  14. $returnArray = array();
  15. foreach ($position as $key => $pos) {
  16. $returnArray[] = $newRow[$key];
  17. }
  18. return $returnArray;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.