
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements