Return to Snippet

Revision: 53474
at November 24, 2011 06:31 by n19ht


Initial Code
function orderMultiDimensionalArray ($toOrderArray, $field, $inverse = false) {
    $position = array();
    $newRow = array();
    foreach ($toOrderArray as $key => $row) {
            $position[$key]  = $row[$field];
            $newRow[$key] = $row;
    }
    if ($inverse) {
        arsort($position);
    }
    else {
        asort($position);
    }
    $returnArray = array();
    foreach ($position as $key => $pos) {     
        $returnArray[] = $newRow[$key];
    }
    return $returnArray;
}

Initial URL

                                

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

Initial Title
Ordenar Array Multidimensional PHP

Initial Tags
php, sort, array, order

Initial Language
PHP