Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

how to generate all sub-array of an array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

how to generate all sub-array of an array

Postby trungtan » Wed Oct 17, 2012 6:14 pm

Hi everyone,

I need to generate all sub-array from an array.

For example:
source_array = array("a", "b", "c", "d");

so the result is:
array(

array("a"), array("b"), array("c"), array("d"),
array("a", "b"), array("a", "c"), array("a", "d"),
array("b", "c"), array("b", "d"),
array("c", "d"),

array("a", "b", "c"), array("a", "b", "d"),
array("a", "c", "d"),
array("b", "c", "d"),

array("a", "b", "c", "d")
)

Please suggest me a good way to do that! Thanks all guys!
trungtan
New php-forum User
New php-forum User
 
Posts: 12
Joined: Mon Nov 28, 2011 3:53 am

Re: how to generate all sub-array of an array

Postby seandisanti » Thu Oct 18, 2012 7:17 am

What you're trying to generate, it sounds like, are all permutations of an array. Search for that phrase on the forum and I think you'll find what you're looking for
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.