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>
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.