PHP code example of axonode / collections

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

    

axonode / collections example snippets


$pair = new \Axonode\Collections\Pair('key', 'value');

$newPair = $pair->withKey('newKey');
$newPair = $pair->withValue('newValue');

$emptyList = new \Axonode\Collections\ArrayList();
$anotherList = new \Axonode\Collections\ArrayList(['item1', 'item2', 'item3']);

// creating an empty dictionary by passing no arguments to the constructor
$emptyDictionary = new \Axonode\Collections\Dictionary();

$key1 = new stdClass();
$key2 = new stdClass();
// creating a dictionary where keys will be `stdClass` instances
$anotherDictionary = new \Axonode\Collections\Dictionary(
    new \Axonode\Collections\Pair($key1, 'value1'),
    new \Axonode\Collections\Pair($key2, 'value2'),
);

// retrieving a value by key
echo $anotherDictionary[$key1]; // 'value1'

$emptySet = new \Axonode\Collections\Set();
$anotherSet = new \Axonode\Collections\ArraySet(['item1', 'item2', 'item2']); // will result in ['item1', 'item2']