PHP code example of dpolac / dictionary

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

    

dpolac / dictionary example snippets



    $dict = new \DPolac\Dictionary();

    $dict[new \stdClass()] = 12;
    $dict['php'] = 23;
    $dict[100] = 'dictionary';


    $dict = new \DPolac\Dictionary();


    $dict = \DPolac\Dictionary::fromPairs([
        ['key1', 'value1'],
        ['key2', 'value2'],
        ['key3', 'value3'],
    ]);


    $dict = \DPolac\Dictionary::fromArray([
        'key1' => 'value1',
        'key2' => 'value2',
        'key3' => 'value3',
    ]);


    $dictionary->sortBy('values','asc');


    $dictionary->sortBy(function($value, $key) {
        return $value->title . $key->name;
    }, 'desc');


    $sortedDictionary = $dictionary->getCopy()->sortBy('values', 'asc');