3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateNumbers() { $numbers = []; while ( count($numbers) < 2 ) { $number = rand(1,5); if ( !in_array($number, $numbers) ) { $numbers[] = $number; } } sort($numbers); return $numbers; } $numbers = generateNumbers(); $new = generateNumbers(); $allNewNumbers = []; $allNewNumbers[] = implode(',',$new); $counter = 1; while ( !empty(array_diff($numbers, $new)) ) { while ( in_array(implode(',',$new),$allNewNumbers) ) { $new = generateNumbers(); } $allNewNumbers[] = implode(',',$new); $counter++; echo 'counter: '.$counter.PHP_EOL; if ( $counter > 1000 ) { echo 'break'.PHP_EOL; break; } } echo 'counter: '.$counter;
Output for 8.2.6, 8.2.8, 8.2.14, 8.2.18, 8.2.27, 8.3.1, 8.3.8, 8.3.10, 8.4.11
counter: 2 counter: 2
Output for 8.2.12, 8.2.16, 8.2.20, 8.2.23, 8.4.6, 8.4.8, 8.4.10
counter: 2 counter: 3 counter: 4 counter: 5 counter: 5
Output for 8.2.11, 8.2.25, 8.2.29, 8.3.21, 8.4.4, 8.4.9
counter: 2 counter: 3 counter: 4 counter: 5 counter: 6 counter: 7 counter: 8 counter: 9 counter: 9
Output for 8.2.0 - 8.2.1, 8.3.12, 8.4.1, 8.4.3, 8.4.7
counter: 2 counter: 3 counter: 4 counter: 4
Output for 8.2.13, 8.3.9, 8.3.19, 8.4.2, 8.4.5
counter: 2 counter: 3 counter: 3
Output for 8.2.7, 8.2.19, 8.2.28, 8.3.6, 8.3.14, 8.3.17, 8.3.24
counter: 2 counter: 3 counter: 4 counter: 5 counter: 6 counter: 6
Output for 8.2.17, 8.2.22, 8.2.24, 8.3.5, 8.3.7, 8.3.11, 8.3.23
counter: 2 counter: 3 counter: 4 counter: 5 counter: 6 counter: 7 counter: 8 counter: 9 counter: 10 counter: 10
Output for 8.2.5, 8.2.9, 8.2.26, 8.3.0, 8.3.3, 8.3.15, 8.3.18, 8.3.20, 8.3.22
counter: 2 counter: 3 counter: 4 counter: 5 counter: 6 counter: 7 counter: 7
Output for 8.2.3 - 8.2.4, 8.3.2, 8.3.16
counter: 2 counter: 3 counter: 4 counter: 5 counter: 6 counter: 7 counter: 8 counter: 8
Output for 8.2.2, 8.2.10, 8.2.15, 8.2.21, 8.3.4, 8.3.13
counter: 1

preferences:
58.49 ms | 418 KiB | 5 Q