Tools, FAQ, Tutorials:
Randomly Retrieving Array Values in PHP
How To Randomly Retrieve a Value from an Array in PHP?
✍: FYIcenter.com
If you have a list of favorite greeting messages, and want to randomly select one of them to be used in an email, you can use the array_rand() function. Here is a PHP example script:
<?php $array = array("Hello!", "Hi!", "Allo!", "Hallo!", "Coucou!"); $key = array_rand($array); print("Random greeting: ".$array[$key]."\n"); ?>
This script will print:
Random greeting: Coucou!
⇒ Looping through an Array without "foreach" in PHP
⇐ Using an Array as a Stack in PHP
2017-01-11, 2345🔥, 0💬
Popular Posts:
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...
How to use the urllib.request.Request object to build more complex HTTP request? The urllib.request....
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...