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, ∼3265🔥, 0💬
Popular Posts:
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...