⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.range.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Create an array containing a range of elements</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.prev.html">prev</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.reset.html">reset</a></div> <div class="up"><a href="ref.array.html">Array Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.range" class="refentry"> <div class="refnamediv">  <h1 class="refname">range</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">range</span> &mdash; <span class="dc-title">Create an array containing a range of elements</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">array</span> <span class="methodname"><b><b>range</b></b></span>    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$low</tt></span>   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$high</tt></span>   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.number" class="type number">number</a></span> <tt class="parameter">$step</tt></span>  ] )</div>  <p class="para rdfs-comment">   Create an array containing a range of elements.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">low</tt></i></span>     <dd>      <p class="para">       Low value.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">high</tt></i></span>     <dd>      <p class="para">       High value.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">step</tt></i></span>     <dd>      <p class="para">       If a <i><tt class="parameter">step</tt></i> value is given, it will be used as the       increment between elements in the sequence.  <i><tt class="parameter">step</tt></i>       should be given as a positive number.  If not specified,       <i><tt class="parameter">step</tt></i> will default to 1.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns an array of elements from <i><tt class="parameter">low</tt></i> to   <i><tt class="parameter">high</tt></i>, inclusive.  If low &gt; high, the sequence will   be from high to low.  </p> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">5.0.0</td>       <td colspan="1" rowspan="1" align="left">        The optional <i><tt class="parameter">step</tt></i> parameter was added.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.1.0 to 4.3.2</td>       <td colspan="1" rowspan="1" align="left">        In PHP versions 4.1.0 through 4.3.2, <b>range()</b> sees        numeric strings as strings and not integers.  Instead, they will be        used for character sequences.  For example, <i>&quot;4242&quot;</i>        is treated as <i>&quot;4&quot;</i>.       </td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.1.0</td>       <td colspan="1" rowspan="1" align="left">        Prior to PHP 4.1.0, <b>range()</b> only generated        incrementing integer arrays.  Support for character sequences and        decrementing arrays was added in 4.1.0.  Character sequence values        are limited to a length of one.  If a length greater than one is        entered, only the first character is used.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>range()</b> examples</b></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">//&nbsp;array(0,&nbsp;1,&nbsp;2,&nbsp;3,&nbsp;4,&nbsp;5,&nbsp;6,&nbsp;7,&nbsp;8,&nbsp;9,&nbsp;10,&nbsp;11,&nbsp;12)<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">12</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$number</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$number</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;The&nbsp;step&nbsp;parameter&nbsp;was&nbsp;introduced&nbsp;in&nbsp;5.0.0<br />//&nbsp;array(0,&nbsp;10,&nbsp;20,&nbsp;30,&nbsp;40,&nbsp;50,&nbsp;60,&nbsp;70,&nbsp;80,&nbsp;90,&nbsp;100)<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$number</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$number</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Use&nbsp;of&nbsp;character&nbsp;sequences&nbsp;introduced&nbsp;in&nbsp;4.1.0<br />//&nbsp;array('a',&nbsp;'b',&nbsp;'c',&nbsp;'d',&nbsp;'e',&nbsp;'f',&nbsp;'g',&nbsp;'h',&nbsp;'i');<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'i'</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$letter</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$letter</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">//&nbsp;array('c',&nbsp;'b',&nbsp;'a');<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #DD0000">'c'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'a'</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$letter</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$letter</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.shuffle.html" class="function" rel="rdfs-seeAlso">shuffle()</a></li>    <li class="member"><a href="function.array-fill.html" class="function" rel="rdfs-seeAlso">array_fill()</a></li>    <li class="member"><a href="control-structures.foreach.html" class="link">foreach</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.prev.html">prev</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.reset.html">reset</a></div> <div class="up"><a href="ref.array.html">Array Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -