What is a treemap in PHP and how is it typically used?

A treemap in PHP is a data structure that stores key-value pairs in a hierarchical tree-like format. It is typically used to represent data in a structured way, where each key is associated with a corresponding value. This data structure allows for efficient retrieval and manipulation of key-value pairs.

// Creating a treemap in PHP
$treemap = [
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3'
];

// Accessing values in the treemap
echo $treemap['key1']; // Output: value1

// Adding a new key-value pair
$treemap['key4'] = 'value4';

// Removing a key-value pair
unset($treemap['key2']);