You could shuffle
the array and then pick the first ten elements with array_slice
:
shuffle($array);
$tenRandomElements = array_slice($array, 0, 10);
More Related Contents:
- How to get random value out of an array?
- Efficiently pick n random elements from PHP array (without shuffle)
- PHP create new array by value
- Get first and second element of array [duplicate]
- Removing array of arrays for certain inner values in PHP
- Can't echo items from array
- How to remove duplicate values from a multi-dimensional array in PHP
- Convert multidimensional array into single array
- PHP Sort Array By SubArray Value
- create array tree from array list
- Finding the subsets of an array in PHP
- Replace keys in an array based on another lookup/mapping array
- Strange behavior of foreach when using reference: foreach ($a as &$v) { … }
- How to sort date array in php?
- php return only duplicated entries from an array
- What’s the disadvantage of mt_rand?
- getting a checkbox array value from POST
- Merge array items into string
- How can I sort an array of UTF-8 strings in PHP?
- Sort array of objects by date field
- Generate an associative array from an array of rows using one column as keys and another column as values
- Native function to filter array by prefix
- Counting occurrence of specific value in an Array with PHP [duplicate]
- Process CSV Into Array With Column Headings For Key
- Print $_POST variable name along with value
- How can I add a condition inside a php array?
- Pass array literal to PostgreSQL function
- Isolate comma-separated values, remove duplicates and empty values, then sort
- Flat PHP Array to Hierarchy Tree
- Remove zero values from a PHP array