PHP code example of alexandr-mironov / multikeyhashmap

1. Go to this page and download the library: Download alexandr-mironov/multikeyhashmap 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/ */

    

alexandr-mironov / multikeyhashmap example snippets




    $collection = new Collection(SomeCLass::class, 'id', 'slug');
        foreach ($iterator as $item) {
            $instance = new SomeClass($item); // just example of entity creating
            $collection->push($instance);
        }

    // after that you can get map by passing name of key
    $idMappedCollection = $collection->getMap('id'); // array with ID as key and SomeClass entity as value
    $slugMappedCollection = $collection->getMap('slug'); // array with SLUG as key and SomeClass entity as value