Posted By

serialk89 on 01/13/12


Tagged

php array order asosiative


Versions (?)

Ordenar array bidimensional por parametro


 / Published in: PHP
 

Ordena Array Bidimensional Asociativo de acuerdo a parametro del array.

  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  

You need to login to post a comment.