这样的事怎么样?每个array_pop()都会从数组中删除一个值,因此您永远不会获得两次相同的值.
// 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...
Run Code Online (Sandbox Code Playgroud)