Table of Contents
php generates a random code with optional digits
Home Backend Development PHP Tutorial PHP generates a random code with optional digits_PHP tutorial

PHP generates a random code with optional digits_PHP tutorial

Jul 12, 2016 am 09:04 AM
Number of digits

php generates a random code with optional digits

<?php
echo coding(6);
function coding($num){
	$str_arr = array(&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;,&#39;h&#39;,&#39;i&#39;,&#39;j&#39;,&#39;k&#39;,&#39;l&#39;,&#39;m&#39;,&#39;n&#39;,&#39;o&#39;,&#39;p&#39;,&#39;q&#39;,&#39;r&#39;,&#39;s&#39;,&#39;t&#39;,&#39;u&#39;,&#39;v&#39;,&#39;w&#39;,&#39;x&#39;,&#39;y&#39;,&#39;z&#39;,&#39;A&#39;,&#39;B&#39;,&#39;C&#39;,&#39;D&#39;,&#39;E&#39;,&#39;F&#39;,&#39;G&#39;,&#39;H&#39;,&#39;I&#39;,&#39;J&#39;,&#39;K&#39;,&#39;L&#39;,&#39;M&#39;,&#39;N&#39;,&#39;O&#39;,&#39;P&#39;,&#39;Q&#39;,&#39;R&#39;,&#39;S&#39;,&#39;T&#39;,&#39;U&#39;,&#39;V&#39;,&#39;W&#39;,&#39;X&#39;,&#39;Y&#39;,&#39;Z&#39;,&#39;0&#39;,&#39;1&#39;,&#39;2&#39;,&#39;3&#39;,&#39;4&#39;,&#39;5&#39;,&#39;6&#39;,&#39;7&#39;,&#39;8&#39;,&#39;9&#39;);
	$rand_s = array_rand($str_arr,$num);
	$code_s = &#39;&#39;;
	if(is_array($rand_s)){
		foreach($rand_s as $v){
			$code_s .= $str_arr[$v];
		}
		return $code_s;
	}else{
		return $str_arr[&#39;rand_s&#39;];
	}
}
?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073353.htmlTechArticlephp generates a random code with optional digits?phpecho coding(6);function coding($num){ $str_arr = array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w ,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How many bits does Windows 10 Pro have? How many bits does Windows 10 Pro have? Dec 25, 2023 pm 05:37 PM

Windows 10 Professional Edition is a very easy-to-use computer system. There are both 64-bit and 32-bit versions, and the 32-bit version is better to use. What we will describe below is an introduction to the advantages of 32-bit version. How many bits is Windows 10 Professional Edition? Answer: Both 32-bit and 64-bit are available. Win10 Professional Edition is available in 32-bit and 64-bit versions. This article mainly introduces the advantages of 32-bit. Let’s take a look. 1. Excellent compatibility performance 1. First of all, we want to emphasize that Windows 10 Professional 32-bit performance is very superior in terms of compatibility. Its extremely high stability allows most existing 32-bit applications to run smoothly. 2. For you, this means enjoying the convenience brought by the latest operating system while

What is the number of bits of binary data that a computer can directly process at one time? What is the number of bits of binary data that a computer can directly process at one time? Aug 20, 2020 pm 03:44 PM

When a computer processes data, the number of bits of binary data that can be directly processed at one time is called the word length. The word length refers to the number of bits of binary data that the computer can directly process at one time. The longer the word length, the stronger the overall performance of the computer.

In C++, the number of digits in the nth number composed of the given four numbers In C++, the number of digits in the nth number composed of the given four numbers Aug 29, 2023 pm 03:01 PM

Weneedtofindthenumberofdigitsinthenthnumbermadeofgivenfourdigits1,2,3,and4.Theserieswiththeabovefourdigitsisasfollows1,2,3,4,11,12,13,14,21,22,23,24...Weneedtofindthenumberofdigitsofthenthnumberfromtheaboveseries.Ifyoucarefullyobservethepattern,youwi

The product of N and the largest odd number of digits in C The product of N and the largest odd number of digits in C Aug 29, 2023 pm 01:25 PM

GivenanumberNwithwehavetoproductthenumberwithitslargestodddigit.Ifthereisnoodddigitthenprint-1.LikewehaveinitializedNwith“153”andthelargestodddigitinthisnumberis5sotheresultwouldbetheproductof153with5i.e.153*5=765andifthenumberhas

Sharing tips on how to determine the number of digits in numbers in PHP Sharing tips on how to determine the number of digits in numbers in PHP Mar 26, 2024 am 11:03 AM

PHP is a popular server-side scripting language that is often used to process numerical data. In actual development, it is often used to determine the number of digits in a number. This article will share some techniques for determining the number of digits in PHP and provide specific code examples. 1. Use the strlen function. The strlen() function in PHP is used to return the length of a string and can also be used to determine the number of digits in an integer. The following is an example code: $num=12345;$length=strlen(

PHP practical code example to determine the number of digits PHP practical code example to determine the number of digits Mar 26, 2024 pm 12:18 PM

Practical code examples for determining the number of digits in PHP. During the development process, sometimes we need to determine the number of digits in a number, such as determining how many digits a number has, or whether a number has a specific number of digits. Below are several practical PHP code examples to implement this function. Determine how many digits a number has: functioncountDigits($num){$count=strlen((string)$num);re

How to count the number of digits in a floating point number in C? How to count the number of digits in a floating point number in C? Sep 08, 2023 pm 10:53 PM

In this question, a floating point value is given. We have to find the number of set bits in its binary representation. For example, if the floating point number is 0.15625, there are six set bits. Typical C compilers use single-precision floating point representation. So it looks like this. To convert to a bit value, we have to put the number into a pointer variable and then cast the pointer to char* type data. Then process each byte one by one. We can then calculate the set bits for each character. Example #include<stdio.h>intchar_set_bit_count(charnumber){ unsigne

How many digits does a PHP timestamp usually have? How many digits does a PHP timestamp usually have? Mar 24, 2024 pm 05:33 PM

PHP timestamps are usually 10 digits and represent the number of seconds that have elapsed from January 1, 1970 00:00:00 UTC to the current time. However, some systems may also use a 13-digit timestamp to represent the number of milliseconds that have elapsed since January 1, 1970 00:00:00 UTC to the current time. Next I will give specific code examples to demonstrate how to use PHP to obtain timestamps with different digits. Get the 10-digit timestamp: //Get the 10-digit timestamp of the current time $timestamp=

See all articles