1
0
mirror of https://github.com/php/doc-fr.git synced 2026-03-24 07:02:06 +01:00
Files
archived-doc-fr/reference/random/examples.xml
2025-08-04 23:06:42 +01:00

67 lines
1.8 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 1bcc40f8134305cbebf6c8378ee7e5fc8c569674 Maintainer: pierrick 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>Exemple Random</title>
<programlisting role="php">
<![CDATA[
<?php
$r = new \Random\Randomizer();
// Génération dun nom de domaine aléatoire
printf(
"%s.example.com\n",
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
);
// Mélanger un tableau :
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
echo "Salade : ", implode(', ', $r->shuffleArray($fruits)), "\n";
// Mélange des clés du tableau
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
$keys = $r->pickArrayKeys($fruits, 2);
// Récupérer les valeurs correspondant aux clés sélectionnées.
$selection = array_map(
static fn ($key) => $fruits[$key],
$keys
);
echo "Valeurs : ", implode(', ', $selection), "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
j87fzv1p0daiwmlo.example.com
Salade: 🥝, 🍇, 🍎, 🍌, 🍑
Valeurs: 🍌, 🍑
]]>
</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
-->