query("UPDATE `-6ren">
gpt4 book ai didi

php - 对 watch 。健康)状况

转载 作者:行者123 更新时间:2023-11-29 06:46:47 27 4
gpt4 key购买 nike

 for ($i=1; $i < 10; $i++) { 
$a = rand(1,6);
$b = rand(1,6);
if ($a != $b) {
$mysqli->query("UPDATE `jpa` SET `war` = $b WHERE `id` = $a");
$mysqli->query("UPDATE `jpa` SET `war` = $a WHERE `id` = $b");
}
}

有必要编制一份对 watch 。执行时得到同样的结果,如何避免这种情况?

最佳答案

从 id 数组开始。

$ids = [1, 2, 3, 4, 5, 6];

随机播放

shuffle($ids);

然后分成 2 个 block 并迭代它们,进行更新。

foreach (array_chunk($ids, 2) as $opponents) {
if (count($opponents) == 2) { // check this in case you have odd numbers of ids
list($a, $b) = $opponents;
$mysqli->query("UPDATE `jpa` SET `war` = $b WHERE `id` = $a");
$mysqli->query("UPDATE `jpa` SET `war` = $a WHERE `id` = $b");
}
}

关于php - 对 watch 。健康)状况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49017934/

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