PHP Classes

PHP Array Intersections: Find intersections between combinations of arrays

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 113 All time: 9,598 This week: 206Up
Version License PHP version Categories
arrayintersections 1.0GNU General Publi...5Algorithms, PHP 5, Tools
Description 

Author

This class can find intersections between combinations of arrays.

It takes a list of arrays and find intersections of common element values.

The class can return all the array intersections, as well the largest array intersection.

Picture of Jelle Sebreghts
  Performance   Level  
Name: Jelle Sebreghts <contact>
Classes: 7 packages by
Country: United States United States
Age: 34
All time rank: 1484223 in United States United States
Week rank: 227 Up23 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Documentation

ArrayIntersections

Build Status Code Climate Test Coverage Issue Count

Tries to find intersections between a combination of arrays.

use Jelle_S\Util\Intersections\ArrayIntersections;

// Get all possible intersections, where the minimum array size of an
// intersection is 3.
$arrays = array(
 array(
   'a' => 1,
   'b' => 2,
   'c' => 3,
   'd' => 4,
   'e' => 9,
 ),
 array(
   'a' => 1,
   'b' => 2,
   'c' => 3,
   'e' => 9,
 ),
 array(
   'a' => 1,
   'b' => 42,
   'c' => 3,
   'd' => 4,

 ),
 array(
   'b' => 42,
   'c' => 3,
   'a' => 1,
 ),
 array(
   'z' => 26,
   'e' => 9,
   'a' => 1,
 ),
);
$intersections = new Jelle_S\Util\Intersections\ArrayIntersections($arrays, 3);
print_r($intersections->getAll());

print_r($intersections->getLargest());

Output:

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

    [1] => Array
        (
            [a] => 1
            [c] => 3
            [d] => 4
        )

    [0] => Array
        (
            [a] => 1
            [b] => 42
            [c] => 3
        )

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

  Files folder image Files (8)  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (8)  /  src  
File Role Description
  Plain text file ArrayIntersections.php Class Class source

  Files folder image Files (8)  /  tests  
File Role Description
  Plain text file ArrayKeyIntersectionsTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadarrayintersections-2017-01-12.zip 16KB
Downloadarrayintersections-2017-01-12.tar.gz 15KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP BitMask Generator Download .zip .tar.gz Composer dependency. Required
 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:113
This week:0
All time:9,598
This week:206Up