Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created December 7, 2011 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/1443239 to your computer and use it in GitHub Desktop.
Save weaverryan/1443239 to your computer and use it in GitHub Desktop.
array rand if statements
<?php
if (count($ids) == 0) {
return array();
}
if (count($ids) < $ct) {
// careful not to request more random numbers than we have in array_rand, it will throw up
$randomIndexes = array_keys($ids);
} else {
$randomIndexes = array_rand($ids, $ct);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment