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.

get $num rand values from array $array

function getRandValueFromArray($num,$array){
$num=$len; // adjust
for($i=0;$i<$num;$i++) {
return $result;

and you can use this code like this: