<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Examples</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.ds-collection.html">Collection</a></div> <div class="up"><a href="book.ds.html">Data Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ds.examples" class="chapter"> <h1>Examples</h1> <div class="example" id="example-5127"> <p><strong>Example #1 Vector</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$vector </span><span style="color: #007700">= new \</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Vector</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$vector</span><span style="color: #007700">-></span><span style="color: #0000BB">push</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$vector</span><span style="color: #007700">-></span><span style="color: #0000BB">push</span><span style="color: #007700">(</span><span style="color: #DD0000">'b'</span><span style="color: #007700">, </span><span style="color: #DD0000">'c'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$vector</span><span style="color: #007700">[] = </span><span style="color: #DD0000">'d'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$vector</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></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="cdata"><pre> Ds\Vector Object ( [0] => a [1] => b [2] => c [3] => d ) </pre></div> </div> </div> <div class="example" id="example-5128"> <p><strong>Example #2 Map</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$map </span><span style="color: #007700">= new \</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Map</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$map</span><span style="color: #007700">-></span><span style="color: #0000BB">put</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$map</span><span style="color: #007700">-></span><span style="color: #0000BB">put</span><span style="color: #007700">(</span><span style="color: #DD0000">'b'</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$map</span><span style="color: #007700">[</span><span style="color: #DD0000">'c'</span><span style="color: #007700">] = </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></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="cdata"><pre> Ds\Map Object ( [0] => Ds\Pair Object ( [key] => a [value] => 1 ) [1] => Ds\Pair Object ( [key] => b [value] => 2 ) [2] => Ds\Pair Object ( [key] => c [value] => 3 ) ) </pre></div> </div> </div> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.ds-collection.html">Collection</a></div> <div class="up"><a href="book.ds.html">Data Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>