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, ∼2712🔥, 0💬
Popular Posts:
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How To Convert a Character to an ASCII Value? If you want to convert characters to ASCII values, you...
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
How To Remove Slashes on Submitted Input Values in PHP? By default, when input values are submitted ...
Where to get the detailed description of the JSON.stringify() Function in JavaScript? Here is the de...