Created
May 22, 2017 11:54
-
-
Save cristinaITdeveloper/d2db22148dcb304ff713c15ca090fb08 to your computer and use it in GitHub Desktop.
PHP get random elements from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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