Home > Backend Development > PHP Tutorial > PHP function shuffle() implements reordering_PHP tutorial

PHP function shuffle() implements reordering_PHP tutorial

WBOY
Release: 2016-07-15 13:33:05
Original
924 people have browsed it

in

shuffle -- shuffle the array:
bool shuffle ( array &array )

PHP function shuffle() shuffle ( Randomly arrange the order of cells) an array.

Note: The PHP function shuffle() assigns new key names to the cells in the array. This will delete the original keys rather than just reorder them.

Example:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">a</span><span> = </span><span class="attribute-value">array</span><span>(  </span></li><li class="alt"><span>'1' =</span><span class="tag">></span><span> 'Xiao',  </span></span></li>
<li>
<span>'2' =</span><span class="tag">></span><span> 'Da',  </span>
</li>
<li class="alt">
<span>'3' =</span><span class="tag">></span><span> 'Zuo',  </span>
</li>
<li>
<span>'4' =</span><span class="tag">></span><span> 'You'  </span>
</li>
<li class="alt"><span>);  </span></li>
<li>
<span>echo "原来的数组:"."</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>";  </span>
</li>
<li class="alt"><span>print_r($a);  </span></li>
<li><span>shuffle($a);  </span></li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>"."现在的数组:"."</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>";  </span>
</li>
<li><span>print_r($a);  </span></li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

Look at the results of the PHP function shuffle():

Original array:

Array ( [1] => Xiao [2] => Da [3] => Zuo [4] => You )

Current array:

Array ( [0] => Da [1] => Xiao [2] => You [3] => Zuo )

Of course, every time the page is refreshed, "Now The order of elements in the array will change once. Notice that the key names of the array have changed.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446075.htmlTechArticleIn shuffle -- shuffle the array: bool shuffle ( array array ) PHP function shuffle() shuffle (randomly The order in which cells are arranged) an array. Note: The PHP function shuffle() is the unit in array...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template