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, 1449👍, 0💬
Popular Posts:
How to use "xml-to-json" Azure API Policy Statement? The "xml-to-json" Policy Statement allows you t...
How to use the API operation 2017 version setting "Rewrite URL template"? The API operation setting ...
How To Add Column Headers to a Table? If you want to add column headers to a table, you need to use ...
How Values in Arrays Are Indexed in PHP? Values in an array are all indexed their corresponding keys...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...