randomicos php sin repetir ayuda | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

randomicos php sin repetir ayuda

tengo esta función pero no se que estoy haciendo mal. que se repiten dos números y quiero que todos sean distintos public function randomico() { $cantidad = 10; $i = 0; $random = rand(1, $cantidad); $array[] = $random; do { for ($i = 0; $i < count($array); $i++) { if ($random == $array[$i]) { $i = 0; $random = rand(1, $cantidad); } } $array[] = $random; } while (count($array) != $cantidad); foreach ($array as $ar) { echo $ar . "<br>"; } }

20th Feb 2018, 9:55 PM
Pablo Gabriel Velasquez Gonzalez
Pablo Gabriel Velasquez Gonzalez - avatar
1 ответ
+ 4
Code output: array(1) { [0]=> int(5) } 5 7 9 2 1 10 8 6 3 4 I think your code works well, there is no repetitive number : )
21st Feb 2018, 8:19 AM
Ipang