Home > Backend Development > PHP Tutorial > PHP permutations

PHP permutations

巴扎黑
Release: 2016-11-23 13:12:24
Original
1126 people have browsed it

<?php
$arr = array(&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;);
combine_array($arr);
function combine_array($arr, $index=0) {
static $num = 0;
$arr_len = count($arr);
if($arr_len == $index) {
++$num;
echo $num.&#39; &#39;. join(",", $arr) . &#39;<br/>&#39;;
} else {
for($i=$index; $i<$arr_len; $i++) {
list($arr[$index], $arr[$i]) = array($arr[$i], $arr[$index]);
combine_array($arr, $index+1);
list($arr[$index], $arr[$i]) = array($arr[$i], $arr[$index]);
}
}
}
Copy after login


Related labels:
php
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