PHP:在文本显示之间交替


PHP: Alternating between text display

我正在使用下面的PHP代码进行A/B拆分。我正在使用秒(奇数与偶数)来触发替代文本显示。我正在寻找另一种均匀替代文本显示的方法。我可以使用其他方法吗?

<?php // A/B Testing ... 
if(fmod(date('s'),'2')=='1') {$hosp_btn='game1'; $hosp_txt='game2';}
   else {$hosp_btn='contact-us'; $hosp_txt='Contact Us';}
?>
<button onClick="ga('send', 'event', 'GameSet', 'game-click', '<?php echo $hosp_btn; ?>');" id="dropdown_button" type="button" href="" class="form-button-view">
                        <?php echo $hosp_txt; ?>
</button>
你可以

使用 rand() 或 mt_rand()。mt_rand生成更好的随机值。

兰德($min, $max)

mt_rand($min、$max)

<?php 
if(mt_rand(0,1)=='1') {
    $hosp_btn='game1'; 
    $hosp_txt='game2';
}else{
    $hosp_btn='contact-us'; 
    $hosp_txt='Contact Us';}
?>
<button onClick="ga('send', 'event', 'GameSet', 'game-click', '<?php echo $hosp_btn; ?>');" id="dropdown_button" type="button" href="" class="form-button-view">
    <?php echo $hosp_txt; ?>
</button>