You could use RecursiveIteratorIterator, RecursiveArrayIterator and iterator_to_array
Your code would then look like this:
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($vals));
$newArray = iterator_to_array($iterator, false);
var_dump($newArray);
and it gives me this result:
array(20) {
[0]=>
int(62)
[1]=>
int(9)
[2]=>
int(5)
[3]=>
int(16)
[4]=>
int(45)
[5]=>
int(11)
[6]=>
int(21)
[7]=>
int(25)
[8]=>
int(32)
[9]=>
int(50)
[10]=>
int(4)
[11]=>
int(23)
[12]=>
int(37)
[13]=>
int(57)
[14]=>
int(13)
[15]=>
int(15)
[16]=>
int(18)
[17]=>
int(22)
[18]=>
int(27)
[19]=>
int(30)
}
We can now select a random value or values from the array like this:
$items = array_rand($newArray, 10);
var_dump($items);
Which would give us these 10 keys:
array(10) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(7)
[6]=>
int(9)
[7]=>
int(13)
[8]=>
int(14)
[9]=>
int(15)
}
We can then loop through those keys and get these values:
int(9)
int(5)
int(16)
int(45)
int(11)
int(25)
int(50)
int(57)
int(13)
int(15)
So in the end you can use this code:
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($vals));
$newArray = iterator_to_array($iterator, false);
$keys = array_rand($newArray, 10);
foreach($keys as $key){
var_dump($newArray[$key]);
}