0% found this document useful (0 votes)
91 views

Generate A Random Order Number in PHP - My Tutorial

The document provides code to generate random order numbers in PHP using arrays and the shuffle function. It shows how to display random numbers and use them in a quiz application by shuffling the order of options each time.

Uploaded by

Odick Tudabit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Generate A Random Order Number in PHP - My Tutorial

The document provides code to generate random order numbers in PHP using arrays and the shuffle function. It shows how to display random numbers and use them in a quiz application by shuffling the order of options each time.

Uploaded by

Odick Tudabit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/7/2020 Generate a random order number in PHP | My Tutorial

PHP <
HTTP://TUTORIAL.DUMBSTRACK.ORG/CATEGORY/PROGRAMMING/PHP/>

Generate a random order number in PHP


By DiCK DuMBSTRaCK < http://tutorial.dumbstrack.org/author/N-OD/>

June 10, 2011 < http://tutorial.dumbstrack.org/generate-a-random-


order-number-in-php/>

1 Comment < http://tutorial.dumbstrack.org/generate-a-random-order-


number-in-php/#comments>

Here is a simple code to generate a random order number in PHP. In my case, I want
to display number item 1, 2, 3, 4, 5 but in random order like:

13452

53241

23514 etc

1 <?php
2 $number = array( 1,2,3,4,5 );
3 for ( $i = 0; $i < 5; $i++ ){
4 shuffle( $number );
5 echo $number&#91;0&#93;;
6 unset( $number&#91;0&#93; );
7 }
8 ?>

For the real world example, hmmm maybe a simple quiz application. The code goes
like this:

tutorial.dumbstrack.org/generate-a-random-order-number-in-php/ 1/3
1/7/2020 Generate a random order number in PHP | My Tutorial

1 <?php
2 echo "Quiz question? <br />";
3 $number = array( 1,2,3,4,5 );
4 $ask = array(
5 "1" => "answer no 1",
6 "2" => "answer no 2",
7 "3" => "answer no 3",
8 "4" => "answer no 4",
9 "5" => "answer no 5"
10 );
11 for ( $i = 0; $i < 5; $i++ ){
12 shuffle( $number );
13 echo "<input type='radio' name='radio' value='".$number
14 unset( $number[0] );
15 }
16 ?>

Taken from my post at TudaBit.com <


http://www.tudabit.com/content/generate-a-random-order-number-in-
php.html> , Hope it’s useful

By DiCK DuMBSTRaCK
Founder of DuMBSTRaCK, like playing music, drawing and writing. Love to
see this nature become a better place :)

View Archive → < http://tutorial.dumbstrack.org/author/N-OD/>

← Buat cadangan kontak ke <


server OVI langsung dari HP http://tutorial.dumbstrack.org/backu
Nokia p-cadangan-kontak-ovi-hp-nokia/>
→ Easiest way to < http://tutorial.dumbstrack.org/blackberry-
upgrade BlackBerry os-upgrade-easiest-online-offline/>
OS

© 2020 My Tutorial < http://tutorial.dumbstrack.org/> Up ↑

tutorial.dumbstrack.org/generate-a-random-order-number-in-php/ 2/3
1/7/2020 Generate a random order number in PHP | My Tutorial

tutorial.dumbstrack.org/generate-a-random-order-number-in-php/ 3/3

You might also like