2017 © Pedro Peláez
 

library powerset

Generate a powerset (enumerate all possible values) of a multi-dimensional array

image

ahungry/powerset

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  • Tuesday, February 6, 2018
  • by ahungry
  • Repository
  • 1 Watchers
  • 0 Stars
  • 175 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Ahungry Powerset

This is a PHP package that allows you to generate a power set (enumerate all possible values) of a multi-dimensional array., (*1)

Installation

Watch for this to be available on packagist, at which point you can install with (update: its on packagist now!):, (*2)

composer require ahungry/powerset

But in the meantime, to install, clone the repository via:, (*3)

git clone https://github.com/ahungry/ahungry-powerset.git

and include the file, or add a new VCS reference in your composer.json as such:, (*4)

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/ahungry/ahungry-powerset"
        }
    ],
    "require": {
        "ahungry/powerset": "^0.1"
    }

then follow it up with a:, (*5)

composer update

Using ahungry-powerset

After requiring it (or auto-loading it with composer), you can use it (see blub.php for a sample) via:, (*6)

use Com\Ahungry\Powerset\Functions as pset;

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

pset\powerSet($b);

print_r($b);

which will then produce the following output:, (*7)

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
        )

)

Oh, and it will work with nested arrays:, (*8)

    $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

TODO

  • Get package listed on packagist, (*9)

  • Generate a true power set (include the empty value possibilities), (*10)

License

GPLv3, (*11)

The Versions

06/02 2018

dev-master

9999999-dev

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3 GPL-3.0-or-later

by Matthew Carter

06/02 2018

0.2.0

0.2.0.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPL-3.0-or-later

by Matthew Carter

20/07 2016

0.1.3

0.1.3.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3

by Matthew Carter

19/07 2016

0.1.2

0.1.2.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3

by Matthew Carter

29/06 2016

0.1.1

0.1.1.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3

by Matthew Carter

29/06 2016

0.1.0

0.1.0.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3

by Matthew Carter

29/06 2016

0.0.1

0.0.1.0

Generate a powerset (enumerate all possible values) of a multi-dimensional array

  Sources   Download

GPLv3

by Matthew Carter