1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-24 07:22:16 +01:00
Files
archived-doc-es/reference/random/examples.xml
2025-08-28 19:59:08 +02:00

67 lines
1.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 1bcc40f8134305cbebf6c8378ee7e5fc8c569674 Maintainer: PhilDaiguille Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="random.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<example>
<title>Ejemplo de aleatoriedad</title>
<programlisting role="php">
<![CDATA[
<?php
$r = new \Random\Randomizer();
// Generar un nombre de dominio aleatorio
printf(
"%s.example.com\n",
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
);
// Mezclar array:
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
echo "Ensalada: ", implode(', ', $r->shuffleArray($fruits)), "\n";
// Mezclar claves de array
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
$keys = $r->pickArrayKeys($fruits, 2);
// Buscar los valores para las claves seleccionadas
$selection = array_map(
static fn ($key) => $fruits[$key],
$keys
);
echo "Valores: ", implode(', ', $selection), "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
j87fzv1p0daiwmlo.example.com
Ensalada: 🥝, 🍇, 🍎, 🍌, 🍑
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
-->