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, 2066🔥, 0💬
Popular Posts:
FYIcenter.com Online Tools: FYIcenter JSON Validator and Formatter FYIcenter JSON to XML Converter F...
How to use the "return-response" Policy statement to build the response from scratch for an Azure AP...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
Where to find EPUB Sample Files? Here is a list of EPUB sample files collected by FYIcenter.com team...
What validation keywords I can use in JSON Schema to specifically validate JSON Array values? The cu...