Created
July 1, 2013 12:43
-
-
Save italoveloso/5900448 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Imprimir(array $values){ | |
foreach($values as $value){ | |
echo $value['id'].' - '.$value['label']; | |
echo '<br />'; | |
} | |
} | |
function Sort_Array(array &$values, $field=NULL){ | |
if (is_null($field) === false){ | |
for($i = 0; $i < sizeof($values); $i++){ | |
for($j = 0; $j < sizeof($values); $j++){ | |
if ($values[$i][$field] < $values[$j][$field]){ | |
$aux = $values[$i]; | |
$values[$i] = $values[$j]; | |
$values[$j] = $aux; | |
} | |
} | |
} | |
} | |
} | |
$dados = array ( | |
array ('id'=>1, 'label' => 'Administracao' ), | |
array ('id'=>3, 'label' => 'Zootecnia' ), | |
array ('id'=>4, 'label' => 'Direito' ), | |
array ('id'=>5, 'label' => 'Biologia' ), | |
array ('id'=>6, 'label' => 'Arquitetura' ), | |
array ('id'=>7, 'label' => 'Biologia' ) | |
); | |
Imprimir($dados); // Imprimindo sem Ordernação | |
Sort_Array($dados,'label'); // Rotina de Ordenação pelo Campo Descrito | |
echo '<br>'; | |
Imprimir($dados); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment