mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Docs for array_rand().
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@28141 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b4a5bcc2ac
commit
f880e69ab8
1 changed files with 57 additions and 5 deletions
|
@ -208,11 +208,9 @@ array_merge ($array1, $array2);
|
|||
"b", "shape" => "trapezoid", 4).
|
||||
</para>
|
||||
</example>
|
||||
<note>
|
||||
<para>
|
||||
This function was added in PHP 4.0.
|
||||
</para>
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
See also <function>array_merge_recursive</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
@ -261,6 +259,9 @@ $result = array_merge_recursive($ar1, $ar2);
|
|||
</para>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
See also <function>array_merge</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
@ -523,6 +524,57 @@ array_push($stack, "+", 3);
|
|||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.array-rand">
|
||||
<refnamediv>
|
||||
<refname>array_rand</refname>
|
||||
<refpurpose>Pick one or more random entries out of an array</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>mixed <function>array_rand</function></funcdef>
|
||||
<paramdef>array <parameter>input</parameter></paramdef>
|
||||
<paramdef>int
|
||||
<parameter><optional>num_req</optional></parameter>
|
||||
</paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
<function>array_rand</function> is rather useful when you want to
|
||||
pick one or more random entries out of an array. It takes an
|
||||
<parameter>input</parameter> array and an optional argument
|
||||
<parameter>num_req</parameter> which specifies how many entries you
|
||||
want to pick - if not specified, it defaults to 1.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you are picking only one entry, <function>array_rand</function>
|
||||
returns the key for a random entry. Otherwise, it returns an array
|
||||
of keys for the random entries. This is done so that you can pick
|
||||
random keys as well as values out of the array.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Don't forget to call <function>srand</function> to seed the random
|
||||
number generator.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<example>
|
||||
<title><function>array_rand</function> example</title>
|
||||
<programlisting role="php">
|
||||
srand((double)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>
|
||||
|
||||
<refentry id="function.array-reverse">
|
||||
<refnamediv>
|
||||
<refname>array_reverse</refname>
|
||||
|
|
Loading…
Reference in a new issue