search

比如我现在有一个数组

$array=Array("a",'b','c','d','e','f','g');

当然不止这么几个

我想要输出的结果是:

a
b
c
d
e
f
g
aa
ab
ac
ad
ae
af
ag
ba
bb
bc
bd
be
bf
bg
ca
cb
cc

…………

gaaaaaaa
gaaaaaab
gaaaaaac
gaaaaaad
gaaaaaae

…………

就是把这些字符能组成的字符串都罗列出来


回复讨论(解决方案)

LZ的问题好像有点歧义吧,比如a这个字母
a算一个 aa算一个  aaa算一个   aaaaaaaaaaaaaaaaaaaaaaaaaa也是一个
要多少是结束啊?

比如我现在有一个数组

$array=Array("a",'b','c','d','e','f','g');

当然不止这么几个

我想要输出的结果是:

a
b
c
d
e
f
g
aa
ab
ac
ad
ae
af
ag
ba
bb
bc
bd
be
bf
bg
ca
cb
cc

…………

gaaaaaaa
gaaaaaab
gaaaaaac
gaaaaaad
gaaaaaae

…………

就是把这些字符能组成的字符串都罗列出来

没问题的,就是要无限个啊。。。

$array=Array("a",'b','c','d','e','f','g');
for($i=-1;$i foreach($array as $k=>$v){
echo $array[$i].$v."
";
}
}
希望能帮到你~

那您这程序啥时候停止啊....

没问题的,就是要无限个啊。。。

那您这程序啥时候停止啊....



没问题的,就是要无限个啊。。。

拔下电源的时候...

估计是想做对撞机


那您这程序啥时候停止啊....



没问题的,就是要无限个啊。。。

拔下电源的时候...

虽然楼主需求看上去有些无厘头,但如果设定好终止条件也并非不能实现
在有限个数的前提下,这个算法还是很具挑战性的
我先来的抛砖引玉

$ar = array("a",'b','c');print_r(allot($ar, 4));print_r(allot($ar, 2));function allot($ar, $num) {  static $st = array(); //用于缓存中间结果  $res = array(); //用于承载返回结果  if(! $st) {    $t = $ar;  }else {    $t = array();    foreach($ar as $v) {      $t = array_merge($t, array_map(        function($item, $prefix) {  return $prefix . $item; },        $st, array_fill(0, count($st), $v)));    }  }//  foreach($t as $v) echo $v . PHP_EOL; //直接产生输出  $res = $st = $t;  if($num > 1) $res = array_merge($res, allot($ar, $num-1));  else $st = array(); //初始缓存,以便下一次调用  return $res;}
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => aa
    [4] => ab
    [5] => ac
    [6] => ba
    [7] => bb
    [8] => bc
    [9] => ca
    [10] => cb
    [11] => cc
    [12] => aaa
    [13] => aab
    [14] => aac
    [15] => aba
    [16] => abb
    [17] => abc
    [18] => aca
    [19] => acb
    [20] => acc
    [21] => baa
    [22] => bab
    [23] => bac
    [24] => bba
    [25] => bbb
    [26] => bbc
    [27] => bca
    [28] => bcb
    [29] => bcc
    [30] => caa
    [31] => cab
    [32] => cac
    [33] => cba
    [34] => cbb
    [35] => cbc
    [36] => cca
    [37] => ccb
    [38] => ccc
    [39] => aaaa
    [40] => aaab
    [41] => aaac
    [42] => aaba
    [43] => aabb
    [44] => aabc
    [45] => aaca
    [46] => aacb
    [47] => aacc
    [48] => abaa
    [49] => abab
    [50] => abac
    [51] => abba
    [52] => abbb
    [53] => abbc
    [54] => abca
    [55] => abcb
    [56] => abcc
    [57] => acaa
    [58] => acab
    [59] => acac
    [60] => acba
    [61] => acbb
    [62] => acbc
    [63] => acca
    [64] => accb
    [65] => accc
    [66] => baaa
    [67] => baab
    [68] => baac
    [69] => baba
    [70] => babb
    [71] => babc
    [72] => baca
    [73] => bacb
    [74] => bacc
    [75] => bbaa
    [76] => bbab
    [77] => bbac
    [78] => bbba
    [79] => bbbb
    [80] => bbbc
    [81] => bbca
    [82] => bbcb
    [83] => bbcc
    [84] => bcaa
    [85] => bcab
    [86] => bcac
    [87] => bcba
    [88] => bcbb
    [89] => bcbc
    [90] => bcca
    [91] => bccb
    [92] => bccc
    [93] => caaa
    [94] => caab
    [95] => caac
    [96] => caba
    [97] => cabb
    [98] => cabc
    [99] => caca
    [100] => cacb
    [101] => cacc
    [102] => cbaa
    [103] => cbab
    [104] => cbac
    [105] => cbba
    [106] => cbbb
    [107] => cbbc
    [108] => cbca
    [109] => cbcb
    [110] => cbcc
    [111] => ccaa
    [112] => ccab
    [113] => ccac
    [114] => ccba
    [115] => ccbb
    [116] => ccbc
    [117] => ccca
    [118] => cccb
    [119] => cccc
)
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => aa
    [4] => ab
    [5] => ac
    [6] => ba
    [7] => bb
    [8] => bc
    [9] => ca
    [10] => cb
    [11] => cc
)

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
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

HTTP Method Verification in LaravelHTTP Method Verification in LaravelMar 05, 2025 pm 04:14 PM

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

Discover File Downloads in Laravel with Storage::downloadDiscover File Downloads in Laravel with Storage::downloadMar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

See all articles

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft