I have a simple array like this:
$input = array('Line1', 'Line2', 'Line3');
And want to echo one of the values randomly. I've done this before but can't remember how I did it and all the examples of array_rand seem more complex that what I need.
Can any help? Thanks
echo $input[array_rand($input)];
array_rand() returns the key, so we need to plug it back into $input
to get the value.
Complex? Are we on the same manual page?
$rand_key = array_rand($input, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With