【问题标题】:take variable in outer function in php在php的外部函数中取变量
【发布时间】:2022-08-19 15:07:55
【问题描述】:

我需要帮助将$total 变量转换为return $seed = ( rand(\'1\',\'10\') * $seed + 5) % $this->total;。谁能帮我?

public function index()
{       
    $total = $this->m_soal->count_soal();
    

    function lcm_rand($seed) {
        return function() use (& $seed ) {

            return $seed = ( rand(\'1\',\'10\') * $seed + 5) % $this->total;
        };
    }
     
}
  • 你能添加你的完整代码吗

标签: php codeigniter error-handling


【解决方案1】:

不知道为什么你需要内部函数,但也许这样的东西会对你有所帮助。

private int $total = 5; // for testing purposes

public function lcm_rand($seed)
{
    return ((random_int(1, 10) * $seed) + 5) % $this->total;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2012-08-27
    • 2012-07-14
    相关资源
    最近更新 更多