lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at
PHP: pick random element from array
For some reason, this isn't second nature for me yet:

$_index = array_rand($ARRAY);

$random_element = $ARRAY[$_index];

I think this can also be done in one step like this:

$random_element = $ARRAY[array_rand($ARRAY)];

Both only work for picking one element from array.

keywords: PHP, array_rand, array, random