Oct 21, 2011

PHP Multidimensional Array Shuffle | Shuffle Array In PHP

Multi-Dimensional array is an array within array. It is the most common used php function to store multiple values within a variable.

Here is my small snippet share for shuffling multidimentional array values.

Just call this function and pass the multidimensional array through parameters.


[php]public static function shuffle_array($array)
if (!is_array($array)) return $array;
$keys = array_keys($array);
shuffle($keys);
$random = array();
foreach ($keys as $key) {
$shuffle[] = $array[$key];
}
return $shuffle;
}
[/php]

2 comments :