<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="ds-map.remove" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>Ds\Map::remove</refname>
  <refpurpose>Removes and returns a value by key</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <modifier>public</modifier> <type>mixed</type><methodname>Ds\Map::remove</methodname>
   <methodparam><type>mixed</type><parameter>key</parameter></methodparam>
   <methodparam choice="opt"><type>mixed</type><parameter>default</parameter></methodparam>
  </methodsynopsis>
  <para>
    Removes and returns a value by key, or return an optional default value if the key
    could not be found.
  </para>

  <note>
    <para>
        Keys of type <type>object</type> are supported.

        If an object implements <classname>Ds\Hashable</classname>,
        equality will be determined by the object's <code>equals</code> function.

        If an object does not implement <classname>Ds\Hashable</classname>,
        objects must be references to the same instance to be considered equal.
    </para>
  </note>

  <note>
    <para>
        You can also use array syntax to access values by key, eg. <code>$map["key"]</code>.
    </para>
  </note>

  <caution>
    <para>
        Be careful when using array syntax. Scalar keys will be coerced to
        integers by the engine. For example, <code>$map["1"]</code> will attempt
        to access <code>int(1)</code>, while <code>$map-&gt;get("1")</code> will
        correctly look up the string key.
    </para>
    <para>
        See <link linkend="language.types.array">Arrays</link>.
    </para>
  </caution>

 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <variablelist>
   <varlistentry>
    <term><parameter>key</parameter></term>
    <listitem>
     <para>
        The key to remove.
     </para>
    </listitem>
   </varlistentry>
   <varlistentry>
    <term><parameter>default</parameter></term>
    <listitem>
     <para>
        The optional default value, returned if the key could not be found.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
    The value that was removed, or the <parameter>default</parameter>
    value if provided and the <parameter>key</parameter> could not be found in the map.
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <para>
   <classname>OutOfBoundsException</classname> if the key could not be found
   and a default value was not provided.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title><function>Ds\Map::remove</function> example</title>
   <programlisting role="php">
<![CDATA[
<?php
$map = new \Ds\Map(["a" => 1, "b" => 2, "c" => 3]);

var_dump($map->remove("a"));      //  1
var_dump($map->remove("e", 10));  // 10 (default used)
?>
]]>
   </programlisting>
   &example.outputs.similar;
   <screen>
<![CDATA[
int(1)
int(10)
]]>
   </screen>
  </example>
 </refsect1>


</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
