PHP code example of carlosv2 / map

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

    

carlosv2 / map example snippets


$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map['string'] = 'string';
$map[1] = 'integer';
$map[true] = 'boolean';
$map[new \stdClass()] = 'object';

foreach ($map as $key => $value) {
    var_dump($key, $value);
}

$obj = new \stdClass();

$map = new Map();
$map[$obj] = 'value';

$map->has($obj); // true
$map->has([]); // false

$map = new Map();

$map->set($key, $value); // Equivalent to: $map[$key] = $value;

$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map[true] = 'boolean';

$newMap = $map->map(function ($value, $key) { return json_encode($key) . '_' . $value; });
$newMap->keys(); // [null, [], true]
$newMap->values(); // ['null_null', '[]_array', 'true_boolean']