Creates a Map from the given KeyedTraversable, or an empty Map if null is passed

public function __construct(
  ?KeyedTraversable<Tk, Tv> $iterable = NULL,
): void;



  • void


This example shows how to create a Map from various KeyedTraversables:

// Create a new string-keyed Map from an associative array
$m = new Map(darray[
  'red' => '#ff0000',
  'green' => '#00ff00',
  'blue' => '#0000ff',
  'yellow' => '#ffff00',

// Create a new integer-keyed Map from a Vector
$m = new Map(Vector {'red', 'green', 'blue', '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);