php - Unique number list -
php - Unique number list -
i have html form user selects numbers using checkboxes. numbers set php array this:
<input type="checkbox" name="formnumber[]" value="1" />
there 24 numbers pick 1 24. want output list of 10 unique lines 5 unique numbers per line using numbers array.
e.g.: pick 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 form. output this:
class="lang-none prettyprint-override">2 16 4 1 15 10 13 2 4 5 12 1 3 16 11 etc etc (10 lines)
i got work still duplicate every , then. can come in 5 24 numbers in form , unique random lines of 4 numbers in output.
$i=1; while ($i<=$xresults) { $numbers = $_post['formnumber']; shuffle($numbers); $counter = 0; foreach ($numbers $number1) { echo "<span>$number1</span> "; if(++$counter >= 4) { break; } } $i++; echo '<p>'; } }
so want pick different combinations of 5 of selected boxes.
well, this:
$flip = array_flip($_post['formnumber']); for($i=0; $i<10; $i++) { $combo = array_rand($flip,5); echo implode(" ",$combo)."\n"; }
php
Comments
Post a Comment