Skip to content

Instantly share code, notes, and snippets.

@havvg
Created November 27, 2012 19:12
Show Gist options
  • Save havvg/4156346 to your computer and use it in GitHub Desktop.
Save havvg/4156346 to your computer and use it in GitHub Desktop.
<?php
$count = 5;
$values = range(20, 50);
var_dump(array_values(array_intersect_key($values, array_flip(array_rand($values, $count)))));
/* Example output
array(5) {
[0]=>
int(25)
[1]=>
int(26)
[2]=>
int(30)
[3]=>
int(31)
[4]=>
int(49)
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment