Last Updated: February 25, 2016
· citizenk

Random output from an array in PHP

Let's say you want to output a value between string0 and string7, at random, with PHP:

    $randomString = array(
    print_r($randomString [array_rand($randomString )]);

One point you should be aware of is that, if you leave array_rand empty, it will return the array key, not its value. Hence the repetition of $randomString...