
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Generate random number from 0 – 9 in PHP?
To generate random number in PHP, use rand(). Let’s say the following is our input −
$storedValue ='0123456789';
And we want to display a random value from the above values.
Example
<!DOCTYPE html> <html> <body> <?php $storedValue ='0123456789'; $aRandomValue= $storedValue[rand(0,strlen($storedValue) - 1)]; echo "The random value=",$aRandomValue; ?> </body> </html>
Output
This will produce the following output
The random value=3
- Related Articles
- How can I generate random integers between 0 and 9 using Python?
- Generate array of random unique numbers in PHP?
- Java Program to generate a random number from an array
- Generate Random Float type number in Java
- Generate Random double type number in Java
- C++ program to generate random number
- How to generate a random number in C++?
- How to generate a random number in JavaScript?
- PHP program different ways to generate a random string
- How to generate 6-digit random number in MySQL?
- Java Program to generate random number with restrictions
- Generate a random number with the given specific length in Excel
- Generate Random boolean in Java
- Generate Random bytes in Java
- Generate random numbers in Arduino

Advertisements