$obj = new \stdClass(); $obj->value = 'Value C3'; $mapValue[2][2] = $obj; // mapping pair 4 $mapKey[3] = 'KeyD'; $obj = new \stdClass(); $obj->value = 'Value D'; $mapValue[3] = $obj; // set 3 mappings to map $mapObject->set($mapKey[0], $mapValue[0]); $mapObject->set($mapKey[1], $mapValue[1]); $mapObject->set($mapKey[2], $mapValue[2][0]); $mapObject->set($mapKey[2], $mapValue[2][1]); $mapObject->set($mapKey[2], $mapValue[2][2]); // get 3 mappings from map echo $mapObject->get($mapKey[0])->value; // 'Value A' echo '<br/>'; echo $mapObject->get($mapKey[1])->value; // 'Value B' echo '<br/>'; foreach ($mapObject->get($mapKey[2]) as $obj) { echo $obj->value; // 'Value C1', 'Value C2', 'Value C3' echo '<br/>'; } echo '<br/>'; // count mappings echo count($mapObject); // 3 // remove mapping with String 'Value B'
/** * @depends testSet * @param TreeMap * @return void */ public function testGet(TreeMap $mapObject) { $this->assertEquals($mapObject->get(self::$mapKey[0]), self::$mapValue[0]); $this->assertEquals($mapObject->get(self::$mapKey[1]), self::$mapValue[1]); $value = $mapObject->get(self::$mapKey[2]); $this->assertInternalType('array', $value); $this->assertEquals(count($value), 3); $this->assertEquals($value[0], self::$mapValue[2][0]); $this->assertEquals($value[1], self::$mapValue[2][1]); $this->assertEquals($value[2], self::$mapValue[2][2]); $this->assertNull($mapObject->get(self::$mapKey[3])); }