I have a script that creates two sets of numbers: 1. a list of random numbers 2. a list of match numbers of repeating numbers
But the list of match numbers of repeating numbers is not working properly.
Let me give an example: Random numbers 5-14-5-4-15-12-8-10-18-13-11-25-15-14-2-7-24-22-13-22-16-18-10-11-25-2-18-9-19-8-1-16-1-23-0-16-17-23-21-20-22-21-9-4-20-24-19-16-9-17
Match numbers 3-11-2-6-2-3-2-2-2-2-2-4-3-2-4-3-4-2-2-2-2-2-2-2-2-2
If you look at the random numbers you see the first match number is the correct. After three numbers we have a match so that match number is 3. Then we start counting from the 5 and the next match number is also correct which is 11 and ends at number 15. But then we should have a match after 2 numbers but this does not work out properly.
Can someone assist me here?
<?php
$existing = [];
$repeat_numbers = [];
for ($rnd=1;$rnd<=50;$rnd++)
{
$randoms[] = mt_rand(0,25);
}
echo implode('-',$randoms).PHP_EOL;
echo "<br><br>";
$i = 1;
foreach($randoms as $rnd){
if(in_array($rnd,$existing)){
$repeat_numbers[] = $i;
$i=1;
}
$existing[] = $rnd;
$i++;
}
echo implode('-',$repeat_numbers);
?>