Skip to content

Instantly share code, notes, and snippets.

@italoveloso
Created July 1, 2013 12:43
Show Gist options
  • Save italoveloso/5900448 to your computer and use it in GitHub Desktop.
Save italoveloso/5900448 to your computer and use it in GitHub Desktop.
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