Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$arr = range(0, 9999); // Большой массив для теста
// Вариант 1: Использование shuffle()
$start = microtime(true);
shuffle($arr);
echo "shuffle() время: " . (microtime(true) - $start) . " секунд\n";
// Вариант 2: Самописная реализация
$arr = range(0, 9999);
$cnt = count($arr);
$shuffled = [];
$start = microtime(true);
while ($cnt > 0) {
$shuffled = array_merge($shuffled, array_splice($arr, rand(0, $cnt - 1), 1));
$cnt--;
}
echo "Самописная реализация время: " . (microtime(true) - $start) . " секунд\n";