HH\Map::__construct
Creates a Map
from the given KeyedTraversable
, or an empty Map
if
null
is passed
public function __construct(
?KeyedTraversable<Tk, Tv> $iterable = NULL,
): void;
Parameters
?KeyedTraversable<Tk, Tv> $iterable = NULL
Returns
void
Examples
This example shows how to create a Map
from various KeyedTraversable
s:
// Create a new string-keyed Map from an associative array
$m = new Map(array(
'red' => '#ff0000',
'green' => '#00ff00',
'blue' => '#0000ff',
'yellow' => '#ffff00',
));
var_dump($m);
// Create a new integer-keyed Map from a Vector
$m = new Map(Vector {'red', 'green', 'blue', 'yellow'});
var_dump($m);
object(HH\Map)#1 (4) {
["red"]=>
string(7) "#ff0000"
["green"]=>
string(7) "#00ff00"
["blue"]=>
string(7) "#0000ff"
["yellow"]=>
string(7) "#ffff00"
}
object(HH\Map)#2 (4) {
[0]=>
string(3) "red"
[1]=>
string(5) "green"
[2]=>
string(4) "blue"
[3]=>
string(6) "yellow"
}
This example shows how passing null
to the constructor creates an empty Map
:
// An empty Map is created if null is provided
$m = new Map(null);
var_dump($m);
object(HH\Map)#1 (0) {
}