PHP Classes

PHP Array Key Combiner: Combine arrays finding intersections

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: 83 All time: 10,060 This week: 206Up
Version License PHP version Categories
arraykeycombiner 1.0.0GNU General Publi...5Algorithms, PHP 5, Data types
Description 

Author

This class can combine arrays finding intersections.

It takes a list of arrays and finds intersections between the element values.

The class returns an array with the intersections combined in single elements and added to the master array.

Innovation Award
PHP Programming Innovation award nominee
February 2017
Number 5
Arrays are a very popular data structure in PHP. Often arrays are combined to generate more arrays from the initial arrays.

This package can process a list of arrays to see which are the values they have in common, thus finding the intersections between them.

Manuel Lemos
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: 180 Up22 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Documentation

ArrayKeyCombiner

Build Status Code Climate Test Coverage Issue Count

Combines arrays by searching for intersections and adding them to the master array. Keys are combined using a delimiter.

use Jelle_S\Util\Combiner\ArrayKeyCombiner;

// Search this array of arrays for intersections and extract them, using a
// delimiter to combine the keys. Limit the number of iterations to search for
// intersections to 10.000, limit the minimum size of intersections to 3, set
// the key delimiter to a comma.
$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,
 ),
);
$combiner = new Jelle_S\Util\Combiner\ArrayKeyCombiner($arrays, 3, 10000, ',');
print_r($combiner->combine());

Output:

Array
(
    [4] => Array
        (
            [a] => 1
            [e] => 9
            [z] => 26
        )

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

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

    [2,0] => Array
        (
            [d] => 4
        )

)

The 'a' and 'z' keys of the array with key '4' were not combined because the threshold for combinations is 3, and combining them would result in a combined array with only two elements.

The arrays with keys '2' and '0' were combined because after extracting the combinations, these two arrays were identical, and the threshold has no effect for identical arrays, they are always combined.


  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 ArrayKeyCombiner.php Class Class source

  Files folder image Files (8)  /  tests  
File Role Description
  Plain text file ArrayKeyCombinerTest.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
Downloadarraykeycombiner-2017-01-12.zip 17KB
Downloadarraykeycombiner-2017-01-12.tar.gz 16KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Array Intersections Download .zip .tar.gz Composer dependency. Required
 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:83
This week:0
All time:10,060
This week:206Up