Ordenar array bidimensional por parametro


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

Ordena Array Bidimensional Asociativo de acuerdo a parametro del array.


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.