mirror of
https://github.com/php/doc-pt_br.git
synced 2026-04-29 11:13:21 +02:00
e5ed35c5de
git-svn-id: https://svn.php.net/repository/phpdoc/pt_BR/trunk@94787 c90b9560-bf6c-de11-be94-00142212c4b1
73 lines
2.4 KiB
XML
73 lines
2.4 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- EN-Revision: 1.4 Maintainer: lucasr Status: ready -->
|
|
<!-- splitted from ./pt_BR/functions/array.xml, last change in rev 1.1 -->
|
|
<!-- last change to 'array-rand' in en/ tree in rev 1.13 -->
|
|
<refentry id="function.array-rand">
|
|
<refnamediv>
|
|
<refname>array_rand</refname>
|
|
<refpurpose>
|
|
Retorna um ou mais elementos aleatórios de um array
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrição</title>
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>array_rand</methodname>
|
|
<methodparam><type>array</type><parameter>input</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>num_req</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_rand</function> é bastante útil quando se quer
|
|
conseguir aleatoriamente um ou mais elementos de um array. Ela recebe
|
|
o array <parameter>input</parameter> e outro argumento opcional
|
|
<parameter>num_req</parameter> o qual especifica quantos elementos
|
|
se quer conseguir - se não for especificado, o padrão é 1.
|
|
</para>
|
|
<para>
|
|
Se estiver pegando apenas um elemento, <function>array_rand</function>
|
|
retorna a chave para este elemento aleatório. De outra forma, ele retorna
|
|
um array com as chaves desses elementos aleatórios. Assim é possível
|
|
conseguir chaves e valores aleatórios a partir da mesma função.
|
|
</para>
|
|
<para>
|
|
Não esqueça de chamar a função <function>srand</function> para disparar
|
|
o gerador de números aleatórios.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>array_rand</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
srand ((float) microtime() * 10000000);
|
|
$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
|
|
$rand_keys = array_rand ($input, 2);
|
|
print $input[$rand_keys[0]]."\n";
|
|
print $input[$rand_keys[1]]."\n";
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- 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:"../../../../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
|
|
-->
|