PHP Random number multiple rows

Hello, I’m trying to make this work.
I have this script that print’s seven numbers between 1 and 37.
This works fine, but i like to print many (100) raws of different random numbers between 1 and 37.
Is this possible. Thank you for your help.

<?php
$randomAnswers = array_rand(array_flip(range(1, 37)), 7);
?>
<html>
<head>
</head>
<body>     
<p>The winning numbers are: <?php echo implode(' ', $randomAnswers);?></p>
</body>
</html>

Do you mean something like

<?php 
for ($i = 0; $i < 100; $i++) {
  $randomAnswers = implode(' ', array_rand(array_flip(range(1, 37)), 7));
  echo '<p>The winning numbers are: ' . $randomAnswers . '</p>';
}
?>

This worked perfect. Thank you. Is it also possible to: print the 7 numbers that are printed most times in this 100 raws?
That is if for ex, number 5 is shown 88 times and number 32 is shown 102 times i want a raw at the bottom that shows this. And wy can’t i use the echo row inside the body tag, here it only show one row?

Sure. :-) You have that array with keys from 1 to 37 anyway, which can also serve as a counter if you just increment the corresponding value by 1 for each occurrence, like

// The array of possible numbers, where
// each value (which will be the occurrence
// count) is initialised with 0
$numbers = array_fill(1, 37, 0);

for ($i = 0; $i < 100; $i++) {

  // Random numbers of the iteration
  $randomAnswers = array_rand($numbers, 7);

  // Increase the counter for the current random 
  // numbers
  foreach ($randomAnswers as $number) {
    $numbers[$number]++;
  }

  echo '<p>The winning numbers are: ' . implode(' ', $randomAnswers) . '</p>';
}

foreach ($numbers as $key => $value) {
  echo "<p>Number {$key} appeard {$value} times</p>";
}

This is great, but this shows how many times number 1-37 apperes I would like it to only show the top 7 numbers that apperes most times. Thank you so much.
And stil if i move the echo “

Number {$key} appeard {$value} times

”; inside the body tag it only shows 1 row?
Thank’s again.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.