note 96956 added to function.shuffle
| From: | rick at suggestive dot com | Date: | Wed, 24 Mar 2010 22:19:05 +0000 |
| Subject: | note 96956 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167369@lists.php.net to get a copy of this message | ||
Many people in SEO need to supply an array and shuffle the results and need the same result each
time that page is generated. This is my implementation with a working example:
<?
function seoShuffle(&$items,$string) {
mt_srand(strlen($string));
for ($i = count($items) - 1; $i > 0; $i--){
$j = @mt_rand(0, $i);
$tmp = $items[$i];
$items[$i] = $items[$j];
$items[$j] = $tmp;
}
}
$items =
array('one','two','three','four','five','six');
$string = 'whatever';
echo '<pre>';
print_r($items);
echo '</pre>';
seoShuffle($items,$string);
echo '<pre>';
print_r($items);
echo '</pre>';
?>
----
Server IP: 69.147.83.197
Probable Submitter: 98.177.229.175
----
Manual Page -- http://www.php.net/manual/en/function.shuffle.php
Edit -- https://master.php.net/note/edit/96956
Del: integrated -- https://master.php.net/note/delete/96956/integrated
Del: useless -- https://master.php.net/note/delete/96956/useless
Del: bad code -- https://master.php.net/note/delete/96956/bad+code
Del: spam -- https://master.php.net/note/delete/96956/spam
Del: non-english -- https://master.php.net/note/delete/96956/non-english
Del: in docs -- https://master.php.net/note/delete/96956/in+docs
Del: other reasons-- https://master.php.net/note/delete/96956
Reject -- https://master.php.net/note/reject/96956
Search -- https://master.php.net/manage/user-notes.php