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, ∼2832🔥, 0💬
Popular Posts:
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...
What Is Azure API Management Service? Azure API Management as a turnkey solution for publishing APIs...
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...