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, ∼3574🔥, 0💬
Popular Posts:
How to call a function from a VC# class provided in a library? If you want to call a function from a...
What is Azure API Management Developer Portal? Azure API Management Developer Portal is an Azure Web...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
What is Azure API Management Publisher Dashboard? Azure API Management Publisher Dashboard is an Azu...
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...