dongsimang4036 2019-06-11 09:26 采纳率: 100%
浏览 79

之后是否有可能使混洗数组不变?

I have a card game with mixed cards (array with 100 cards, value 1-100, shuffled - alternative would be to random pick by id).

Each player gets a set of cards. The cards are played with POST/ submit.

My problem is that every time I post, the cards are mixed again. But the value of the cards should stay constant while assigned to card-variables.

Is there any possibility to make a random constant afterwards, so that the variable doesn´t get re-assigned when posting/loading?

function mixcarddeck()
{
    $carddeck = array(100);
    for ($i = 0; $i < 100; $i++) {
        $carddeck[$i] = $i + 1;
    }
    shuffle($carddeck);
}

function givecardvalue($i)
{
    $carddeck = mixcarddeck();
    return $carddeck[$i];
}

Thanks a lot in advance!

  • 写回答

1条回答 默认 最新

  • dongye9071 2019-06-11 09:39
    关注

    you can use $$ to make a dynamic variable in php instead of single $ if thats, what u want

     $variable="name";
        $$variable;
    
    $$variabe is now (same as $name)
    

    now generate random constant and make new variables each time so that new variable is assigned each time

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)