PHP code example of konekod / evenly-distribute

1. Go to this page and download the library: Download konekod/evenly-distribute 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/ */

    

konekod / evenly-distribute example snippets



// See EvenlyDistributeServiceTest::testExampleWorksFine

$input = [
        ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]],
        ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]],
        ['poolId' => 'B', 'uniqueEntityId' => '678', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 678]],
];

$output = EvenlyDistributeService::distributeByPools($input);

$excepted = [
    'A' => [
        ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]]
    ],
    'B' => [
        ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]]
    ],
];

echo $excepted === $output;