I have an array:
$input2 = array("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"). I need to remove a random element from there from an array and display this element on the screen and then remove this element from the array.
I have an array:
$input2 = array("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"). I need to remove a random element from there from an array and display this element on the screen and then remove this element from the array.
$i = rand(0, count($input2) - 1); echo $input2[$i]; unset($input2[$i]); header('Location: http://php.net/docs.php'); at the end header('Location: http://php.net/docs.php'); ... barely resist -)) - AlexandrX Nov.unset() does not shift indices. And, you may still need to call array_merge() so that the indices go without gaps - Anton Shchyrov $arr = ["S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"]; while($arr) { shuffle($arr); //перемешивает массив echo array_pop($arr); //извлекает последний элемент массива уменьшая его //можно так же использовать array_shift() } Source: https://ru.stackoverflow.com/questions/592299/
All Articles