random_element()

random_element($array)

Parameters:
  • $array (array) – Input array
Returns:

A random element from the array

Return type:

mixed

Takes an array as input and returns a random element from it.

Usage example:

$quotes = array(
        "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
        "Don't stay in bed, unless you can make money in bed. - George Burns",
        "We didn't lose the game; we just ran out of time. - Vince Lombardi",
        "If everything seems under control, you're not going fast enough. - Mario Andretti",
        "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",
        "Chance favors the prepared mind - Louis Pasteur"
);

echo random_element($quotes);
doc_CodeIgniter
2016-10-15 16:32:35
Comments
Leave a Comment

Please login to continue.