PHP Classes
elePHPant
Icontem

PHP Array Key Combiner: Combine arrays finding intersections

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-01-12 (4 months ago) RSS 2.0 feedNot enough user ratingsTotal: 60 All time: 8,820 This week: 686Up
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
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.

Manuel Lemos
  Performance   Level  
Name: Jelle Sebreghts <contact>
Classes: 7 packages by
Country: Belgium Belgium
Innovation award
Innovation award
Nominee: 4x

Details

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  
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  /  src  
File Role Description
  Plain text file ArrayKeyCombiner.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file ArrayKeyCombinerTest.php Class Class source

Downloadarraykeycombiner-2017-01-12.zip 17KB
Downloadarraykeycombiner-2017-01-12.tar.gz 15KB
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:60
This week:0
All time:8,820
This week:686Up