Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. /*
  3. A função sort() ordena um array indexado em ordem crescente.
  4.  
  5. Dica: Use o rsort() para ordenar uma matriz indexada em ordem decrescente.
  6.  
  7. Sintaxe: sort(array,sortingtype);
  8.  
  9. Parâmetros:
  10. array - Obrigatório. Especifica a matriz que será classificada.
  11. sortingtype - Opcional. Especifica como comparar os elementos da matriz.
  12. Valores possíveis:
  13. 0 = SORT_REGULAR - Padrão. Compara itens normalmente (não modifica o tipo)
  14. 1 = SORT_NUMERIC - Compara itens numericamente
  15. 2 = SORT_STRING - Comparaa os itens como strings
  16. 3 = SORT_LOCALE_STRING - Compara os itens como strings, com base na localidade atual
  17. 4 = SORT_NATURAL - Compara os itens como strings usando ordenação natural
  18. 5 = SORT_FLAG_CASE
  19.  
  20. EXEMPLO 1
  21. Organizar os elementos do array $cars em ordem alfabética ascendente:
  22. */
  23. $cars=array("Volvo","BMW","Toyota");
  24. sort($cars);
  25. print_r($cars);
  26. /*
  27. Saída: Array ( [0] => BMW [1] => Toyota [2] => Volvo )
  28. */
  29. ?>
  30.  
  31.  
  32. <?php
  33. /*
  34. EXEMPLO 2
  35. Organizar os elementos do array $numbers em ordem numérica crescente:
  36. */
  37. $numbers=array(4,6,2,22,11);
  38. sort($numbers);
  39. print_r($numbers);
  40. /*
  41. Saída: Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 11 [4] => 22 )
  42. */
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement