Posted By

n19ht on 11/24/11


Tagged

php sort array ordenar order asort


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

guillermoj88gmailcom


Ordenar Array Multidimensional PHP


 / Published in: PHP
 

Ordena cualquier array multidimensional en base a un campo especĂ­fico

  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  

You need to login to post a comment.