You can also do just:
$k = array_rand($array);
$v = $array[$k];
This is the way to do it when you have an associative array.
More Related Contents:
- Efficiently pick n random elements from PHP array (without shuffle)
- How do I select 10 random things from a list in PHP?
- Can I bind an array to an IN() condition in a PDO query?
- PHP random string generator
- How to generate a random, unique, alphanumeric string?
- PHP Constants Containing Arrays?
- Preserve key order (stable sort) when sorting with PHP’s uasort
- Fatal error: Cannot use object of type mysqli_result [closed]
- Group array by subarray values
- Remove all elements from array that do not start with a certain string
- php – How do I fix this illegal offset type error
- Posting multidimensional array with PHP and CURL
- Recursively remove empty elements and subarrays from a multi-dimensional array
- PHP array_filter with arguments
- How to convert an array into an object using stdClass() [duplicate]
- Unexpected bracket ‘[‘ – PHP [duplicate]
- scandir() to sort by date modified
- Print the keys of an array
- How to delete object from array inside foreach loop?
- Sort Object in PHP
- Best method for sum two arrays [closed]
- Notice: Undefined index when trying to increment an associative array in PHP
- PHP – Get key name of array value
- What is the max key size for an array in PHP?
- Generate cryptographically secure random numbers in php
- Sort array by value alphabetically php
- Change array key without changing order
- Moving array element to top in PHP
- phpexcel Allowed memory size of 134217728 bytes exhausted [duplicate]
- PHP, pass array through POST