gpt4 book ai didi

php - ARRAY_RAND 始终具有相同的输出

转载 作者:行者123 更新时间:2023-12-03 09:26:34 26 4
gpt4 key购买 nike

这是什么,我在 php 中有一个任务,我需要随机选择一张卡,然后使用一个名为“draw”的按钮来抓取另一张随机卡。

            <td><b>Rectangle 10</b></br>

<p>Your card is: </p>

<?php
$cards = array("AC","AD","AH","AS","1C","1D","1H","1S",
"2C","2D","2H","2S","3C","3D","3H","3S","4C","4D","4H","4S",
"5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S",
"8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S",
"JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS"
);
$card = array_rand($cards, '1');
print_r($cards[$card]);
?>

<form>
<input type="button" value="Draw" onClick="window.location.reload()">
</form>

</td>

代码本身可以工作,但在整个页面中却不能,我现在将粘贴整个页面。

<?php
$today = date_default_timezone_set('Europe/London');
$a = 3034;
srand($a);
?>

<table border='1'>
<tr>
<td><b>Rectangle 1</b></br>Rob Dorsett </br> 12007071 </br><?php echo $today = date('d/m/y')?></td>
<td><b>Rectangle 2</b></br><?php echo $addition = (3+4+5) ?></td>
</tr>

<tr>
<td><b>Rectangle 3</b></br> <?php srand(3034);
echo (rand()); ?> </td>

<td><b>Rectangle 4</b></br>
<?php for ($i=30;$i<=40;$i++){
if($i%2 == 0) {
echo $i. '</br>';}
}
?>
</td>
</tr>


<tr>
<td><b>Rectangle 5</b></br>

<form>
</br>
Enter four digits: </br>
<input name="input" />
</br><input type="submit" value="Sumbit" />
</form>
<?php
$x = $_GET['input'];
?>
</td>

<td><b>Rectangle 6</b></br>

<?php
if ($x%2 == 0){
echo 'Your number is even';
}
else
{
echo 'Your number is odd';
}
?>
</td>

</tr>

<td><b>Rectangle 7</b></br>
<form>
Enter a seed for a random number: </br>
<input type="text" name="random" /> </br>
<input type="submit" value="Generate" /> </br>
<?php
$r7 = $_GET['random'];
srand($r7);
echo rand();
?>
</form>


</td>
<td><b>Rectangle 8</b></br>
<?php
echo str_rot13('Example Rot13');
?>
</br>
<i>Example Rot13</i>

</td>
<tr>
<td><b>Rectangle 9</b></br>

<script type="text/javascript">
function rot13 (txt) {
var map = []
var tmp = "abcdefghijklmnopqrstuvwxyz"
var buf = ""

for (j = 0; j < tmp.length; j++) {
var x = tmp.charAt(j); var y = tmp.charAt((j + 13) % 26)
map[x] = y; map[x.toUpperCase()] = y.toUpperCase()
}

for (j = 0; j < txt.length; j++) {
var c = txt.charAt(j)
buf += (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' ? map[c] : c)
}

return buf
}
</script>

<script>var foo = rot13 ('Example Rot13')</script>
<p>Encoded: <script>document.write(foo)</script>
<p>Decoded: <script>document.write(rot13(foo))</script>

</td>


<td><b>Rectangle 10</b></br>

<p>Your card is: </p>

<?php
$cards = array("AC","AD","AH","AS","1C","1D","1H","1S",
"2C","2D","2H","2S","3C","3D","3H","3S","4C","4D","4H","4S",
"5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S",
"8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S",
"JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS"
);
$card = array_rand($cards, '1');
print_r($cards[$card]);
?>

<form>
<input type="button" value="Draw" onClick="window.location.reload()">
</form>

</td>
</tr>
</table>

最佳答案

您正在向 srand() 函数提供静态值,因此您始终会得到相同的结果。另外,看看我最后的评论。

关于php - ARRAY_RAND 始终具有相同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com