问下怎么生成所有的不重复的数组

WBOY
Release: 2016-06-23 13:45:45
Original
887 people have browsed it

比如 ab
生成
ab
ba
比如  a b c
生成所有的
abc
acb
bac
bca
cab
cba


回复讨论(解决方案)

$str    = 'abc';$res    = Arrangement( $str );print_r($res);function Arrangement($arr = array(), $res = '') {  if(! is_array($arr) ) $arr = str_split($arr);  if(empty($arr)) $array[] = $res;  else foreach($arr AS $k => $v) {    unset($arr[$k]);    foreach( Arrangement($arr, $res . $v) AS $t) $array[] = $t;    $arr[$k]    = $v;  }  return  $array;}
Copy after login
Array(    [0] => abc    [1] => acb    [2] => bca    [3] => bac    [4] => cab    [5] => cba)
Copy after login

非常感谢,是我要的效果

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!