Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- A função sort() ordena um array indexado em ordem crescente.
- Dica: Use o rsort() para ordenar uma matriz indexada em ordem decrescente.
- Sintaxe: sort(array,sortingtype);
- Parâmetros:
- array - Obrigatório. Especifica a matriz que será classificada.
- sortingtype - Opcional. Especifica como comparar os elementos da matriz.
- Valores possíveis:
- 0 = SORT_REGULAR - Padrão. Compara itens normalmente (não modifica o tipo)
- 1 = SORT_NUMERIC - Compara itens numericamente
- 2 = SORT_STRING - Comparaa os itens como strings
- 3 = SORT_LOCALE_STRING - Compara os itens como strings, com base na localidade atual
- 4 = SORT_NATURAL - Compara os itens como strings usando ordenação natural
- 5 = SORT_FLAG_CASE
- EXEMPLO 1
- Organizar os elementos do array $cars em ordem alfabética ascendente:
- */
- $cars=array("Volvo","BMW","Toyota");
- sort($cars);
- print_r($cars);
- /*
- Saída: Array ( [0] => BMW [1] => Toyota [2] => Volvo )
- */
- ?>
- <?php
- /*
- EXEMPLO 2
- Organizar os elementos do array $numbers em ordem numérica crescente:
- */
- $numbers=array(4,6,2,22,11);
- sort($numbers);
- print_r($numbers);
- /*
- Saída: Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 11 [4] => 22 )
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement