Home > Backend Development > PHP Tutorial > 新人 怎么生成不重复的4位数字

新人 怎么生成不重复的4位数字

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:36:45
Original
943 people have browsed it

新人求助 如何生成不重复的4位数字
//随即生成四位数
function sc(){
  for($i=0;$i $ygsz=rand(0,9);
$sgesz.=$ygsz;
}
  for($a=0;$a if($sgesz[$a]==$sgesz[$a+1]){
$vv=sc();
}



  }
  return $sgesz;
}
$zqsz=sc();





?>
怎么改呢

------解决方案--------------------

PHP code
function sc() {    $ar = array();    for ($i = 0; $i <font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
 $arr = Array('0','1','2','3','4','5','6','7','8','9');//定义数组 shuffle($arr);//打乱元素顺序 $rand = array_slice($arr,0,4);//取前四个元素 $result=implode('',$rand);//转成字符串 echo $result;<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template