// Get your data into an array (since there's only 30 rows):
$result = mysqli_query($connection, "SELECT * FROM table LIMIT 3;");
$rows = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$rows[] = $row;
}
// Randomise the array:
shuffle($rows);
// Get first random value:
$row = array_pop($rows);
print ($row['value']);
// Get second random value:
$row = array_pop($rows);
print ($row['value']);
// etc...
1条答案
按热度按时间6tr1vspr1#
像这样的怎么样?每个数组\u pop()都会从数组中删除一个值,因此您永远不会两次获得相同的值。