How to Get Some Random Values From a Array in PHP

if you have an array which contains 10 elements, and you want to get 5 random values in this array, how to realize? I think source code below will help you.

<?php
 /**
get $num rand values from array $array
*/

function getRandValueFromArray($num,$array){
$len=count($array);
if($len<$num){
$num=$len; // adjust
}
$result=array();
for($i=0;$i<$num;$i++) {
$count=$len-1-$i;
$index=rand(0,$count);
$result[$i]=$array[$index];
$temp=$array[$count];
$array[$count]=$array[$index];
$array[$index]=$temp;
}
return $result;
}
 ?>

and you can use this code like this:

 <?php
 $array=array("a","b","c","d","e");
 $num=6;
 $result=getRandValueFromArray($num,$array);
 print_r($result);
 ?>