日期:2014-05-17 浏览次数:20526 次
$last = '';
$r = '';
for($i=0; $i<10; $i++) {
$t = rand(0, 1)>0.5 ? 'a' : 'b';
$r .= $t == $last ? '0' : $t;
$last = $t;
}
echo $r;
------解决方案--------------------
<?php
function chkStr($a,$b)
{
$str='';
$c='';
$d='';
$arr=array($a,$b);
while(strlen($str)<10)
{
$d=rand(0,1);
$str.=($c==$arr[$d]) ? ("0") : ($arr[$d]);
$c=($c==$arr[$d]) ? ("0") : ($arr[$d]);
}
return $str;
}
echo chkStr(a,b);
?>