You can do:
<?php
$min = 1; // Minimum 1 time
$max = 10; // Maximum 10 times
$string = "Hello world!\n"; // Print Hello World! and a new line
$x = rand($min,$max); // Make the random
$i = 0; // Set the iterator
do {
echo $string; // Echo the text
$i = $i + 1; // Increment the iterator
} while ($i < $x); // Test to make sure we didn't do it too many times
?>
This echo
s “Hello world!” anywhere from 1 to 10 times. You can search the PHP API to see how this works.
2
solved How to echo same sentence random times in php? [closed]