PHP/Data Structure/shuffle — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:37, 26 мая 2010
Randomizing an Array Using shuffle(), kshuffle(), and array_rand()
<source lang="html4strict">
<?php
$nums = array(15, 2.2, -4, 2.3, 0); shuffle($nums);printf("
%s\n", var_export($nums, TRUE));
shuffle($nums);printf("
%s\n", var_export($nums, TRUE));
shuffle($nums);printf("
%s\n", var_export($nums, TRUE));
?>
</source>
shuffle( ) function randomizes the position of the elements
<source lang="html4strict">
<?
$natural_born_killers = array("lions", "tigers", "bears", "kittens"); shuffle($natural_born_killers);
?>
</source>
shuffle.php
<source lang="html4strict">
<?php $cards = array("a","b","c","d","e","f","g","h"); shuffle($cards); print_r($positions); ?>
</source>