<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.array-rand.php',
    1 => 'array_rand',
    2 => 'Estrae a caso uno o pi&ugrave; elementi da un array',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.array-push.php',
    1 => 'array_push',
  ),
  'next' => 
  array (
    0 => 'function.array-reduce.php',
    1 => 'array_reduce',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/array/functions/array-rand.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-rand" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_rand</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_rand</span> &mdash; <span class="dc-title">
     Estrae a caso uno o più elementi da un array
    </span></p>

   </div>
   <div class="refsect1 unknown-1519" id="refsect1-function.array-rand-unknown-1519">
    <h3 class="title">Descrizione</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>array_rand</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$input</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$num_req</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_rand()</strong></span> è piuttosto utile quando si vuole
     estrarre a caso  uno o più elementi da un array. Prende un
     array (<code class="parameter">input</code>) e un argomento ozpionale
     (<code class="parameter">num_req</code>) che specifica quanti elementi
     estrarre - se non è specificato, è 1 per default.
    </p>
    <p class="para">
     Se si sta estraendo solo un elemento, <span class="function"><strong>array_rand()</strong></span>
     restituisce la chiave di un elemento. Altrimenti, restituisce un array
     di chiavi. Questo viene fatto in modo da permettere di estrarre
     dall&#039;array sia le chiavi che i valori.
    </p>
    
    <blockquote class="note"><p><strong class="note">Nota</strong>: <span class="simpara">Dal PHP 4.2.0, non c&#039;è più bisogno
di inizializzare il generatore di nomeri casuali con <span class="function"><a href="function.srand.php" class="function">srand()</a></span> o
<span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span> dal momento che questo viene fatto automaricamente.
</span></p></blockquote>

    <p class="para">
     <div class="example" id="example-1">
      <p><strong>Example #1 esempio di <span class="function"><strong>array_rand()</strong></span></strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">&lt;?<br />srand((float) microtime() * 10000000);<br />$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");<br />$chiavi = array_rand($input, 2);<br />echo $input[$chiavi[0]] . "\n";<br />echo $input[$chiavi[1]] . "\n";<br />?&gt;</span></code></div>
      </div>

     </div>
    </p>
    <p class="para">
     Vedere anche <span class="function"><a href="function.shuffle.php" class="function">shuffle()</a></span>.
    </p>
   </div>

  </div><?php manual_footer($setup); ?>