mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
65 lines
1.8 KiB
XML
65 lines
1.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?><!-- EN-Revision: 1bcc40f8134305cbebf6c8378ee7e5fc8c569674 Maintainer: leonardolara Status: ready --><!-- CREDITS: fernandowobeto, leonardolara -->
|
|
<chapter xml:id="random.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Exemplo de Random</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$r = new \Random\Randomizer();
|
|
|
|
// Gerando um nome de domínio aleatório
|
|
printf(
|
|
"%s.example.com\n",
|
|
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
|
|
);
|
|
|
|
// Embaralhando um array:
|
|
$fruits = [ 'vermelho' => '🍎', 'verde' => '🥝', 'amarelo' => '🍌', 'rosa' => '🍑', 'roxo' => '🍇' ];
|
|
echo "Salada: ", implode(', ', $r->shuffleArray($fruits)), "\n";
|
|
|
|
// Embaralhando chaves de array
|
|
$fruits = [ 'vermelho' => '🍎', 'verde' => '🥝', 'amarelo' => '🍌', 'rosa' => '🍑', 'roxo' => '🍇' ];
|
|
|
|
$keys = $r->pickArrayKeys($fruits, 2);
|
|
// Procurando os valores para as chaves escolhidas.
|
|
$selection = array_map(
|
|
static fn ($key) => $fruits[$key],
|
|
$keys
|
|
);
|
|
|
|
echo "Valores: ", implode(', ', $selection), "\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
j87fzv1p0daiwmlo.example.com
|
|
Salada: 🥝, 🍇, 🍎, 🍌, 🍑
|
|
Valores: 🍌, 🍑
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</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
|
|
-->
|