Home > Backend Development > PHP Tutorial > PHP求给定数组的组合

PHP求给定数组的组合

WBOY
Release: 2016-06-23 13:33:35
Original
796 people have browsed it

1、求给定数组的组合

如array('a', 'b', 'c')

结果为

a

b

c

a b

a c

b c

function combination($arr){    if(empty($arr)){        return false;    }    $count = count($arr);    for($i=1; $i';        return true;    }    if($begin == $end){        return false;    }    array_push($result, $arr[$begin]);    combinationResult($arr, $begin+1, $end, $number-1);    array_pop($result);    combinationResult($arr, $begin+1, $end, $number);}$arr = array('a', 'b', 'c', 'd');combination($arr);
Copy after login


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