w3resource
php Programming Exercies

PHP Array Exercises : Generate unique random numbers within a range

PHP Array: Exercise-15 with Solution

Write a PHP script to generate unique random numbers within a range.

Sample Range : (11, 20)

Sample Solution:

PHP Code:

<?php
$n=range(11,20);
shuffle($n);
for ($x=0; $x< 10; $x++)
{
echo $n[$x].' ';
}
echo "\n"
?>

Sample Output:

17 19 13 15 20 14 12 18 11 16    

Flowchart:

Flowchart: Generate unique random numbers within a range

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP script to get the shortest/longest string length from an array.
Next: Write a PHP script to get the largest key in an array.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming