PHP simple shuffling algorithm_PHP tutorial
- WBOYOriginal
- 2016-07-13 10:37:47902browse
<p>Source: http://phpman.cn/?p=37 <br>
<strong>Tag: </strong> <None>
</p>
<h2>
Code snippet<em>(1)</em>
</h2>
<h3>
<i>[Code]</i> [PHP]Code</h3>
view source
<embed allowscriptaccess="always" flashvars="highlighterId=highlighter_372062" height="16" id="highlighter_372062_clipboard" menu="false" src="http://www.oschina.net/js/syntax-highlighter-2.1.382/scripts/clipboard.swf" title="copy to clipboard" type="application/x-shockwave-flash" width="16" wmode="transparent"></embed>
print?
<tbody>
<code>01</code>
<code class="plain"><?php</code>
</tbody>
<tbody>
<code>02</code>
<code class="comments">/**</code>
</tbody>
<tbody>
<code>03</code>
<code class="spaces"> </code><code class="comments">* @author phpman.cn</code>
</tbody>
<tbody>
<code>04</code>
<code class="spaces"> </code><code class="comments">* @date 2012/12/04</code>
</tbody>
<tbody>
<code>05</code>
<code class="spaces"> </code><code class="comments">* @todo 简单洗牌算法</code>
</tbody>
<tbody>
<code>06</code>
<code class="spaces"> </code><code class="comments">*/</code>
</tbody>
<tbody>
<code>07</code>
</tbody>
<tbody>
<code>08</code>
<code class="variable">$card_num</code><code class="plain">=54; </code><code class="comments">//牌数</code>
</tbody>
<tbody>
<code>09</code>
<code class="plain">print_r(wash_card(</code><code class="variable">$card_num</code><code class="plain">));</code>
</tbody>
<tbody>
<code>10</code>
</tbody>
<tbody>
<code>11</code>
<code class="keyword">function</code> <code class="plain">wash_card(</code><code class="variable">$card_num</code><code class="plain">)</code>
</tbody>
<tbody>
<code>12</code>
<code class="plain">{</code>
</tbody>
<tbody>
<code>13</code>
<code class="spaces"> </code><code class="variable">$cards</code><code class="plain">=</code><code class="variable">$tmp</code><code class="plain">=</code><code class="keyword">array</code><code class="plain">();</code>
</tbody>
<tbody>
<code>14</code>
<code class="spaces"> </code><code class="keyword">for</code><code class="plain">(</code><code class="variable">$i</code><code class="plain">=0;</code><code class="variable">$i</code><code class="plain"><</code><code class="variable">$card_num</code><code class="plain">;</code><code class="variable">$i</code><code class="plain">++){</code>
</tbody>
<tbody>
<code>15</code>
<code class="spaces"> </code><code class="variable">$tmp</code><code class="plain">[</code><code class="variable">$i</code><code class="plain">]=</code><code class="variable">$i</code><code class="plain">;</code>
</tbody>
<tbody>
<code>16</code>
<code class="spaces"> </code><code class="plain">}</code>
</tbody>
<tbody>
<code>17<code>17</code>
</tbody>
<tbody>
<code>18<code>18</code>
<code class="spaces"> <code class="spaces"> </code><code class="keyword">for<code class="keyword">for</code><code class="plain">(<code class="plain">(</code><code class="variable">$i<code class="variable">$i</code><code class="plain">=0;<code class="plain">=0;</code><code class="variable">$i<code class="variable">$i</code><code class="plain"><<code class="plain"><</code><code class="variable">$card_num<code class="variable">$card_num</code><code class="plain">;<code class="plain">;</code><code class="variable">$i<code class="variable">$i</code><code class="plain">++){<code class="plain">++){</code>
</tbody>
<tbody>
<code>19<code>19</code>
<code class="spaces"> <code class="spaces"> </code><code class="variable">$index<code class="variable">$index</code><code class="plain">=rand(0,<code class="plain">=rand(0,</code><code class="variable">$card_num<code class="variable">$card_num</code><code class="plain">-<code class="plain">-</code><code class="variable">$i<code class="variable">$i</code><code class="plain">-1);<code class="plain">-1);</code>
</tbody>
<tbody>
<code>20<code>20</code>
<code class="spaces"> <code class="spaces"> </code><code class="variable">$cards<code class="variable">$cards</code><code class="plain">[<code class="plain">[</code><code class="variable">$i<code class="variable">$i</code><code class="plain">]=<code class="plain">]=</code><code class="variable">$tmp<code class="variable">$tmp</code><code class="plain">[<code class="plain">[</code><code class="variable">$index<code class="variable">$index</code><code class="plain">];<code class="plain">];</code>
</tbody>
<tbody>
<code>21<code>21</code>
<code class="spaces"> <code class="spaces"> </code><code class="plain">unset(<code class="plain">unset(</code><code class="variable">$tmp<code class="variable">$tmp</code><code class="plain">[<code class="plain">[</code><code class="variable">$index<code class="variable">$index</code><code class="plain">]);<code class="plain">]);</code>
</tbody>
<tbody>
<code>22<code>22</code>
<code class="spaces"> <code class="spaces"> </code><code class="variable">$tmp<code class="variable">$tmp</code><code class="plain">=<code class="plain">=</code><code class="functions">array_values<code class="functions">array_values</code><code class="plain">(<code class="plain">(</code><code class="variable">$tmp<code class="variable">$tmp</code><code class="plain">);<code class="plain">);</code>
</tbody>
<tbody>
<code>23<code>23</code>
<code class="spaces"> <code class="spaces"> </code><code class="plain">}<code class="plain">}</code>
</tbody>
<tbody>
<code>24<code>24</code>
<code class="spaces"> <code class="spaces"> </code><code class="keyword">return<code class="keyword">return</code> <code class="variable">$cards<code class="variable">$cards</code><code class="plain">;<code class="plain">;</code>
</tbody>
<tbody>
<code>25<code>25</code>
<code class="plain">}<code class="plain">}</code>
</tbody>
<tbody>
<code>26<code>26</code>
<code class="plain">?><code class="plain">?></code>
</code>
</tbody>
<br>
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/735158.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/735158.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">来源:http://phpman.cn/?p=37 标签: 无 代码片段 (1) [代码] [PHP]代码 view source print? 01 ?php 02 /** 03 * @author phpman.cn 04 * @date 2012/12/04 05 * @todo 简单洗牌...</span>
</div>
<div class="art_confoot"></div>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn