Write a php script to generate a random from the following l

Write a php script to generate a random from the following list of numbers

a) 1 to 50 (one from the list)

b) 6, 12, 18, 24, 30 (one from the list)

c) 7, 13, 19, 25, 31 (one from the list)

d) 3 to 75 (one from the list)

Solution

a)
The php script that generates a random number
in a range of 1 to 50 using rand function
and print to browser.

<?php
echo rand(1, 50);

b)
The below script that creates an array of given array
and generates a random number from the Array
<?php
$values = Array(6, 12, 18, 24, 30);
echo $values[array_rand($values)];

c)
The below script that creates an array of given array
and generates a random number from the Array
<?php
$values = Array(7, 13, 19, 25, 31);
echo $values[array_rand($values)];

d)
The php script that generates a random number
in a range of 3 to 75 using rand function
and print to browser.

<?php
echo rand(3, 75);

Write a php script to generate a random from the following list of numbers a) 1 to 50 (one from the list) b) 6, 12, 18, 24, 30 (one from the list) c) 7, 13, 19,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site