<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.ds-set.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'ds-set.add.php',
    1 => 'Ds\\Set::add',
    2 => 'Adds values to the set',
  ),
  'up' => 
  array (
    0 => 'class.ds-set.php',
    1 => 'Ds\\Set',
  ),
  'prev' => 
  array (
    0 => 'class.ds-set.php',
    1 => 'Ds\\Set',
  ),
  'next' => 
  array (
    0 => 'ds-set.allocate.php',
    1 => 'Ds\\Set::allocate',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ds/ds/set/add.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="ds-set.add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Ds\Set::add</h1>
  <p class="verinfo">(PECL ds &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Set::add</span> &mdash; <span class="dc-title">Adds values to the set</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-ds-set.add-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Ds\Set::add</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
    Adds all given values to the set that haven&#039;t already been added.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
        Values of type <span class="type"><a href="language.types.object.php" class="type object">object</a></span> are supported.

        If an object implements <span class="classname"><a href="class.ds-hashable.php" class="classname">Ds\Hashable</a></span>,
        equality will be determined by the object&#039;s <code class="code">equals</code> function.

        If an object does not implement <span class="classname"><a href="class.ds-hashable.php" class="classname">Ds\Hashable</a></span>,
        objects must be references to the same instance to be considered equal.
    </p>
  </p></blockquote>
  <div class="caution"><strong class="caution">Caution</strong>
    <p class="para">
        All comparisons are strict (type and value).
    </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-ds-set.add-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">values</code></dt>
    <dd>
     <p class="para">
        Values to add to the set.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-ds-set.add-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    No value is returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-ds-set.add-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>Ds\Set::add()</strong></span> example using integers</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$set </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Ds\Set</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Strict comparison would not treat these the same as int(1)<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #DD0000">"1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$set</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(Ds\Set)#1 (5) {
  [0]=&gt;
  int(1)
  [1]=&gt;
  int(2)
  [2]=&gt;
  int(3)
  [3]=&gt;
  string(1) &quot;1&quot;
  [4]=&gt;
  bool(true)
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="function"><strong>Ds\Set::add()</strong></span> example using objects</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">HashableObject </span><span style="color: #007700">implements </span><span style="color: #0000BB">\Ds\Hashable<br /></span><span style="color: #007700">{<br />    </span><span style="color: #FF8000">/**<br />     * An arbitrary value to use as the hash value. Does not define equality.<br />     */<br />    </span><span style="color: #007700">private </span><span style="color: #0000BB">$value</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)<br />    {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">value </span><span style="color: #007700">= </span><span style="color: #0000BB">$value</span><span style="color: #007700">;<br />    }<br /><br />    public function </span><span style="color: #0000BB">hash</span><span style="color: #007700">()<br />    {<br />        return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">value</span><span style="color: #007700">;<br />    }<br /><br />    public function </span><span style="color: #0000BB">equals</span><span style="color: #007700">(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">): </span><span style="color: #0000BB">bool<br />    </span><span style="color: #007700">{<br />        return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">value </span><span style="color: #007700">=== </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">value</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$set </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Ds\Set</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">\ArrayIterator</span><span style="color: #007700">([]);<br /><br /></span><span style="color: #FF8000">// Adding the same instance multiple times will only add the first.<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Adding multiple instances of the same object will add them all.<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\stdClass</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\stdClass</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">// Adding multiple instances of equal hashable objects will only add the first.<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\HashableObject</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\HashableObject</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\HashableObject</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$set</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(new </span><span style="color: #0000BB">\HashableObject</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$set</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(Ds\Set)#1 (5) {
  [0]=&gt;
  object(ArrayIterator)#2 (1) {
    [&quot;storage&quot;:&quot;ArrayIterator&quot;:private]=&gt;
    array(0) {
    }
  }
  [1]=&gt;
  object(stdClass)#3 (0) {
  }
  [2]=&gt;
  object(stdClass)#4 (0) {
  }
  [3]=&gt;
  object(HashableObject)#5 (1) {
    [&quot;value&quot;:&quot;HashableObject&quot;:private]=&gt;
    int(1)
  }
  [4]=&gt;
  object(HashableObject)#6 (1) {
    [&quot;value&quot;:&quot;HashableObject&quot;:private]=&gt;
    int(2)
  }
}</pre>
</div>
   </div>
  </div>
 </div>



</div><?php manual_footer($setup); ?>