mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
170 lines
5.1 KiB
XML
170 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: d1df62fe77b6cb0676d064e8e63ee2c3304d4260 Maintainer: leonardolara Status: ready --><!-- CREDITS: thiago, airtonzanon, leonardolara -->
|
|
|
|
<chapter xml:id="array.sorting" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>Ordenando Arrays</title>
|
|
<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.
|
|
</para>
|
|
<para>
|
|
As principais diferenças são:
|
|
</para>
|
|
<para>
|
|
<simplelist>
|
|
<member>
|
|
Algumas ordenam com base nas chaves do <type>array</type>, enquanto outras
|
|
pelos valores: <literal>$array['chave'] = 'valor';</literal>
|
|
</member>
|
|
<member>
|
|
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, ...)
|
|
</member>
|
|
<member>
|
|
A ordem da ordenação: alfabética, ascendente (menor para maior),
|
|
descendente (maior para menor), natural, aleatório, ou definida pelo usuário
|
|
</member>
|
|
<member>
|
|
Nota: Todas essas funções agem diretamente na própria variável do array,
|
|
ao invés de retornar um novo array ordenado
|
|
</member>
|
|
<member>
|
|
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).
|
|
</member>
|
|
</simplelist>
|
|
</para>
|
|
<para>
|
|
<table>
|
|
<title>Atributos das funções de ordenação</title>
|
|
<tgroup cols="5">
|
|
<thead>
|
|
<row>
|
|
<entry>Nome da função</entry>
|
|
<entry>Ordena por</entry>
|
|
<entry>Mantém a associação de chaves</entry>
|
|
<entry>Ordenação</entry>
|
|
<entry>Funções relacionadas</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><function>array_multisort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry><type>string</type> chaves sim, <type>int</type> chaves não</entry>
|
|
<entry>primeiro array ou opções de ordenação</entry>
|
|
<entry><function>array_walk</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>asort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>sim</entry>
|
|
<entry>ascendente</entry>
|
|
<entry><function>arsort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>arsort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>sim</entry>
|
|
<entry>descendente</entry>
|
|
<entry><function>asort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>krsort</function></entry>
|
|
<entry>chave</entry>
|
|
<entry>sim</entry>
|
|
<entry>descendente</entry>
|
|
<entry><function>ksort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>ksort</function></entry>
|
|
<entry>chave</entry>
|
|
<entry>sim</entry>
|
|
<entry>ascendente</entry>
|
|
<entry><function>krsort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>natcasesort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>sim</entry>
|
|
<entry>natural, insensível a maiúsculas/minúsculas</entry>
|
|
<entry><function>natsort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>natsort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>sim</entry>
|
|
<entry>natural</entry>
|
|
<entry><function>natcasesort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>rsort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>não</entry>
|
|
<entry>descendente</entry>
|
|
<entry><function>sort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>shuffle</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>não</entry>
|
|
<entry>aleatória</entry>
|
|
<entry><function>array_rand</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>sort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>não</entry>
|
|
<entry>menor para maior</entry>
|
|
<entry><function>rsort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>uasort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>sim</entry>
|
|
<entry>definida pelo usuário</entry>
|
|
<entry><function>uksort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>uksort</function></entry>
|
|
<entry>chave</entry>
|
|
<entry>sim</entry>
|
|
<entry>definida pelo usuário</entry>
|
|
<entry><function>uasort</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>usort</function></entry>
|
|
<entry>valor</entry>
|
|
<entry>não</entry>
|
|
<entry>definida pelo usuário</entry>
|
|
<entry><function>uasort</function></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
</para>
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|