<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'array.sorting.php',
    1 => 'Ordenando Arrays',
    2 => 'Ordenando Arrays',
  ),
  'up' => 
  array (
    0 => 'book.array.php',
    1 => 'Arrays',
  ),
  'prev' => 
  array (
    0 => 'array.constants.php',
    1 => 'Constantes predefinidas',
  ),
  'next' => 
  array (
    0 => 'ref.array.php',
    1 => 'Fun&ccedil;&otilde;es para Array',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'reference/array/sorting.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="array.sorting" class="chapter">
 <h1 class="title">Ordenando Arrays</h1>

 <p class="para">
  O PHP tem muitas funções para lidar com ordenação de arrays, e esse
  documento existe para ajudar o desenvolvedor a lidar com elas.
 </p>
 <p class="para">
  As principais diferenças são:
 </p>
 <p class="para">
  <ul class="simplelist">
   <li>
    Algumas ordenam com base nas chaves do <span class="type"><a href="language.types.array.php" class="type array">array</a></span>, enquanto outras
    pelos valores: <code class="literal">$array[&#039;chave&#039;] = &#039;valor&#039;;</code>
   </li>
   <li>
    A correlação entre as chaves e os valores do array não são mantidas depois
    da ordenação, o que pode fazer com que as chaves sejam resetadas
    numericamente (0, 1, 2, ...)
   </li>
   <li>
    A ordem da ordenação: alfabética, ascendente (menor para maior),
    descendente (maior para menor), natural, aleatório, ou definida pelo usuário
   </li>
   <li>
    Nota: Todas essas funções agem diretamente na própria variável do array,
    ao invés de retornar um novo array ordenado
   </li>
   <li>
    Se qualquer uma dessas funções avaliar dois membros como iguais
    então eles retém sua ordem original.
    Antes do PHP 8.2.0, sua ordem eram indefinida (a ordenação não é estável).
   </li>
  </ul>
 </p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>Atributos das funções de ordenação</strong></caption>
   
    <thead>
     <tr>
      <th>Nome da função</th>
      <th>Ordena por</th>
      <th>Mantém a associação de chaves</th>
      <th>Ordenação</th>
      <th>Funções relacionadas</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><span class="function"><a href="function.array-multisort.php" class="function">array_multisort()</a></span></td>
      <td>valor</td>
      <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span> chaves sim, <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> chaves não</td>
      <td>primeiro array ou opções de ordenação</td>
      <td><span class="function"><a href="function.array-walk.php" class="function">array_walk()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.asort.php" class="function">asort()</a></span></td>
      <td>valor</td>
      <td>sim</td>
      <td>ascendente</td>
      <td><span class="function"><a href="function.arsort.php" class="function">arsort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.arsort.php" class="function">arsort()</a></span></td>
      <td>valor</td>
      <td>sim</td>
      <td>descendente</td>
      <td><span class="function"><a href="function.asort.php" class="function">asort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.krsort.php" class="function">krsort()</a></span></td>
      <td>chave</td>
      <td>sim</td>
      <td>descendente</td>
      <td><span class="function"><a href="function.ksort.php" class="function">ksort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.ksort.php" class="function">ksort()</a></span></td>
      <td>chave</td>
      <td>sim</td>
      <td>ascendente</td>
      <td><span class="function"><a href="function.krsort.php" class="function">krsort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.natcasesort.php" class="function">natcasesort()</a></span></td>
      <td>valor</td>
      <td>sim</td>
      <td>natural, insensível a maiúsculas/minúsculas</td>
      <td><span class="function"><a href="function.natsort.php" class="function">natsort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.natsort.php" class="function">natsort()</a></span></td>
      <td>valor</td>
      <td>sim</td>
      <td>natural</td>
      <td><span class="function"><a href="function.natcasesort.php" class="function">natcasesort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.rsort.php" class="function">rsort()</a></span></td>
      <td>valor</td>
      <td>não</td>
      <td>descendente</td>
      <td><span class="function"><a href="function.sort.php" class="function">sort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.shuffle.php" class="function">shuffle()</a></span></td>
      <td>valor</td>
      <td>não</td>
      <td>aleatória</td>
      <td><span class="function"><a href="function.array-rand.php" class="function">array_rand()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.sort.php" class="function">sort()</a></span></td>
      <td>valor</td>
      <td>não</td>
      <td>menor para maior</td>
      <td><span class="function"><a href="function.rsort.php" class="function">rsort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.uasort.php" class="function">uasort()</a></span></td>
      <td>valor</td>
      <td>sim</td>
      <td>definida pelo usuário</td>
      <td><span class="function"><a href="function.uksort.php" class="function">uksort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.uksort.php" class="function">uksort()</a></span></td>
      <td>chave</td>
      <td>sim</td>
      <td>definida pelo usuário</td>
      <td><span class="function"><a href="function.uasort.php" class="function">uasort()</a></span></td>
     </tr>

     <tr>
      <td><span class="function"><a href="function.usort.php" class="function">usort()</a></span></td>
      <td>valor</td>
      <td>não</td>
      <td>definida pelo usuário</td>
      <td><span class="function"><a href="function.uasort.php" class="function">uasort()</a></span></td>
     </tr>

    </tbody>
   
  </table>

 </p>
</div>
<?php manual_footer($setup); ?>