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, ∼3437🔥, 0💬
Popular Posts:
How to use the "find-and-replace" Policy Statement for an Azure API service operation? The "find-and...
How to install "The Windows SDK version 8.1"? I need to build my Visual Studio C++ applications. If ...
How to use the urllib.request.Request object to build more complex HTTP request? The urllib.request....
How To Set session.gc_divisor Properly in PHP? As you know that session.gc_divisor is the frequency ...
Where to find tutorials on EPUB file format? I want to know how to create EPUB books. Here is a larg...