fork(1) download
  1. <?php
  2.  
  3. $a = array('orange', 'apple', 'banana', 'pine');
  4.  
  5. $len = count($a);
  6. $list = array();
  7.  
  8. for ($i = 1; $i < (1 << $len); $i++) {
  9. $c = [];
  10. for ($j = 0; $j < $len; $j++) {
  11. if ($i & (1 << $j)) {
  12. $c[] = $a[$j];
  13. }
  14. }
  15. $list[] = $c;
  16. }
  17.  
  18. print_r($list);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => orange
        )

    [1] => Array
        (
            [0] => apple
        )

    [2] => Array
        (
            [0] => orange
            [1] => apple
        )

    [3] => Array
        (
            [0] => banana
        )

    [4] => Array
        (
            [0] => orange
            [1] => banana
        )

    [5] => Array
        (
            [0] => apple
            [1] => banana
        )

    [6] => Array
        (
            [0] => orange
            [1] => apple
            [2] => banana
        )

    [7] => Array
        (
            [0] => pine
        )

    [8] => Array
        (
            [0] => orange
            [1] => pine
        )

    [9] => Array
        (
            [0] => apple
            [1] => pine
        )

    [10] => Array
        (
            [0] => orange
            [1] => apple
            [2] => pine
        )

    [11] => Array
        (
            [0] => banana
            [1] => pine
        )

    [12] => Array
        (
            [0] => orange
            [1] => banana
            [2] => pine
        )

    [13] => Array
        (
            [0] => apple
            [1] => banana
            [2] => pine
        )

    [14] => Array
        (
            [0] => orange
            [1] => apple
            [2] => banana
            [3] => pine
        )

)