Ex.
http://faq.phpmyfaq.de/content/1/9/en/a ... ework.html
Tags :"Firefox Internet Explorer MySQL PHP phpMyFAQ Safari" is no shuffled.
I checked "www.php.net". I found
"5.2.10 The resulting array of keys is no longer shuffled"
array_rand() have bug.
http://www.php.net/manual/en/function.array-rand.php
array_rand($data, count($data)) don't work
I use shuffle(),and work!
Code: Select all
#
####--- Open ------------------------
#
/inc/Utils.php
#
##--- Find ------------------------
# About Line231
public static function shuffleData($data)
{
$shuffled_data = array();
if (is_array($data)) {
if (count($data) > 1) {
$randomized_keys = array_rand($data, count($data));
#
#--- Replace With ------------------------
#
public static function shuffleData($data)
{
$shuffled_data = array();
if (is_array($data)) {
if (count($data) > 1) {
$randomized_keys = array_keys($data);
shuffle($randomized_keys);
###########################
This code is simpler .
Code: Select all
#
###--- OPEN ---------------------
#
/inc/Tags.php
#
## --- Find ---------------------
# About Line108
$numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result);
if (isset($allTags) && ($numberOfItems < count($allTags))) {
$keys = array_keys($allTags);
for ($n = 0; $n < $numberOfItems; $n++) {
$valid = false;
while (!$valid) {
$rand = array_rand($keys);
if (isset($allTags[$rand])) {
$valid = true;
$tags[$rand] = $allTags[$rand];
unset($keys[$rand]);
}
}
}
} else {
$tags = PMF_Utils::shuffleData($allTags);
}
#
## ---- Replase with -----------------
#
$numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result);
if (isset($allTags) && ($numberOfItems < count($allTags))) {
$keys = array_keys($allTags);
shuffle($keys);
foreach($keys as $current_key) {
$tags[$current_key] = $allTags[$current_key];
}
$tags = array_slice($tags,0,$numberOfItems);
} else {
$tags = PMF_Utils::shuffleData($allTags);
}
########################