<?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.range.php',
    1 => 'range',
    2 => 'Crea un array contenente una serie di elementi',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.prev.php',
    1 => 'prev',
  ),
  'next' => 
  array (
    0 => 'function.reset.php',
    1 => 'reset',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/array/functions/range.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.range" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">range</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">range</span> &mdash; <span class="dc-title">
     Crea un array contenente una serie di elementi
    </span></p>

   </div>
   <div class="refsect1 unknown-1597" id="refsect1-function.range-unknown-1597">
   <h3 class="title">Descrizione</h3>
    <div class="methodsynopsis dc-description">
     <span class="methodname"><strong>range</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$min</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$max</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$step</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>range()</strong></span> restituisce una serie di elementi da
     <code class="parameter">min</code> a <code class="parameter">max</code>,
     inclusiva.  Se <code class="parameter">min</code> &gt; <code class="parameter">max</code>, la sequenza sarà decrescente.
    </p>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <strong>Nuovo parametro</strong><br />
     <span class="simpara">
      Il parametro opzionale <code class="parameter">step</code> è stato aggiunto nel PHP 5.0.0.
     </span>
    </p></blockquote>
    <p class="para">
     Se il valore <code class="parameter">step</code> è specificato, verrà utilizzato come
     incremento tra gli elementi della sequenza. <code class="parameter">step</code>
     deve essere un numero positivo. Se non specificato,
     il valore predefinito per <code class="parameter">step</code> è 1. 
    </p>
    <p class="para">
     <div class="example" id="example-1">
      <p><strong>Example #1 esempi di <span class="function"><strong>range()</strong></span></strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">12</span><span style="color: #007700">) as </span><span style="color: #0000BB">$numero</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$numero</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Il parametro step è stato introdotto nel PHP 5.0.0<br />// array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">) as </span><span style="color: #0000BB">$numero</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$numero</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// L'utilizzo dei caratteri è stato aggiunto nel PHP 4.1.0<br />// array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #DD0000">'i'</span><span style="color: #007700">) as </span><span style="color: #0000BB">$lettera</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$lettera</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">// array('c', 'b', 'a');<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #DD0000">'c'</span><span style="color: #007700">, </span><span style="color: #DD0000">'a'</span><span style="color: #007700">) as </span><span style="color: #0000BB">$lettera</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$lettera</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
      </div>

     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      Prima della versione 4.1.0 la funzione <span class="function"><strong>range()</strong></span> generava solo
      array crescenti di interi. Il supporto per le sequenze di caratteri e
      array decrescenti è stata aggiunta nella 4.1.0. I valori delle sequenze di caratteri
      sono limitati alla lunghezza di 1 carattere. Se viene inserito un valore
      con una lunghezza maggiore, viene utilizzato solo il primo carattere.
     </p>
    </p></blockquote>
    <div class="caution"><strong class="caution">Attenzione</strong>
     <p class="para">
      Nel PHP dalla versione 4.1.0 alla 4.3.2, <span class="function"><strong>range()</strong></span> vede
      le stringhe numeriche come stringhe e non come interi. Quindi, verranno 
      utilizzate come sequenze di caratteri. Per esempio, <code class="literal">&quot;4242&quot;</code>
      viene trattato come <code class="literal">&quot;4&quot;</code>.
     </p>
    </div>
    <p class="para">
     Vedere <span class="function"><a href="function.shuffle.php" class="function">shuffle()</a></span>,
     <span class="function"><a href="function.array-fill.php" class="function">array_fill()</a></span> e
     <a href="control-structures.foreach.php" class="link">foreach</a>.
    </p>
   </div>

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