Skip to content

Instantly share code, notes, and snippets.

@cristinaITdeveloper
Created May 22, 2017 11:54
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 cristinaITdeveloper/d2db22148dcb304ff713c15ca090fb08 to your computer and use it in GitHub Desktop.
Save cristinaITdeveloper/d2db22148dcb304ff713c15ca090fb08 to your computer and use it in GitHub Desktop.
PHP get random elements from array
<?php
function get_random_elements($array, $limit = 0 ) {
shuffle($array);
if ( $limit > 0 ) {
$array = array_splice($array, 0, $limit);
}
return $array;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment