note 101253 deleted from function.shuffle by danbrown
| From: | danbrown@php.net | Date: | Mon, 06 Dec 2010 17:59:57 +0000 |
| Subject: | note 101253 deleted from function.shuffle by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174667@lists.php.net to get a copy of this message | ||
Note Submitter: eugene at ultimatecms dot co dot za
----
<?php
// Array Shuffle with a limited return
function shuffle_array($array, $limit=2) {
$limiter = $limit-1;
shuffle($array);
for($c=0; $c<=limiter;$c++) {
$limited_array[] = $array[$c];
}
return $limited_array;
}
$array_values = array('a', 'b', 'c', 'd');
$shuffled_array = shuffle_limit($array_values, 3);
echo '<pre>';
print_r($shuffled_array);
echo '</pre>';
/*
This will output a shuffled array limited to 3 values:
i.e. array('c', 'a', 'd');
*/
?>