This snippet will accept 1 parameter which should be an array. It takes the array, shuffles the array and returns a shuffled array. The new shuffled array will remain the association between keys and values!
Returns array if the input was an array else it will return false!
Use:
$shuffled = shuffle_array($arr);
function shuffle_array($arr)
{
if (is_array($arr))
{
$temp = array();
$final = array();
foreach ($arr as $key => $value)
{
$temp[][$key] = $value;
}
shuffle($temp);
foreach ($temp as $both)
{
while(list($a,$b) = each($both))
{
$final[$a] = $b;
}
}
return $final;
}
else
{
return false;
}
}
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments