簡體   English   中英

實際上在PHP中一定時間運行函數

[英]Actually run a function a certain percentage of the time in PHP

如何在PHP中編寫函數以X%的時間調用給定函數(匿名)?

例如:

function call_weighted(0.1, function() {
      echo 'this is actually run approximately 10% of the times it is called';
});
function call_weighted($weight, $function) {
    if (mt_rand() < $weight * mt_getrandmax()) {
        $function();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM