PHP code example of ahungry / powerset

1. Go to this page and download the library: Download ahungry/powerset library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ahungry / powerset example snippets


use Com\Ahungry\Powerset\Functions as pset;

$b = [[
    'a' => [1,2],
    'b' => [3,4],
]];

pset\powerSet($b);

print_r($b);

Array
(
    [0] => Array
        (
            [a] => 2
            [b] => 4
        )

    [1] => Array
        (
            [a] => 2
            [b] => 3
        )

    [2] => Array
        (
            [a] => 1
            [b] => 4
        )

    [3] => Array
        (
            [a] => 1
            [b] => 3
        )

)

    $a = [[
        'a' => 0,
        'x' => [
          ['b' => 1, 'c' => ['a', 'b', 'c']],
          ['b' => 3, 'c' => ['a', 'b', 'c']],
          ['b' => 5, 'c' => ['a', 'b', 'c']],
        ],
        'y' => [7, 8, 9],
      ]];

    ps\powerSet($a);
    $this->assertCount(27, $a); // true