Home >Backend Development >PHP Tutorial >Examples of php generating all two-digit (numbers, letters) combinations from 0-9, a-z

Examples of php generating all two-digit (numbers, letters) combinations from 0-9, a-z

WBOY
WBOYOriginal
2016-07-25 08:57:563040browse
This article introduces an example of using PHP to generate all two-digit combinations from 0-9, a-z. Friends in need can refer to it.

This section introduces a piece of php code to output any two-digit number composed of numbers and letters.

Thinking Analysis: If the limit is two digits, consider whether the first digit is required to be not 0. If the first digit is allowed to be zero, it will be 36 * 36, that is, a complete arrangement. There are 36 situations in the first place, and there are also 36 situations in the second place. The answer is: The 36 cases in the first place multiplied by the 36 cases in the second place => 36 * 36.

If the first digit is not allowed to be zero, the first digit is 35 cases, and the answer is 35 * 36.

Three to four digits and so on, 36 * 36 * 36 (the first three digits can be zero).

The code is as follows:

<?php
/**
* 生成0-9,a-z任意的二位数组合
* edit by bbs.it-home.org
*/
function all(){
 $jichu = array(0,1,2,3,4,5,6,7,8,9,'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');
 $c = count($jichu );
 for($i=1;$i<=36;$i++){
     $j = $i-1;
     foreach($jichu as $k){
  echo $k.$jichu[$j].'<br />';
     }
 }
}
all();
?>


Statement:
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