<!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>Returns the result of applying a callback to each value</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-deque.last.html">Ds\Deque::last</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-deque.merge.html">Ds\Deque::merge</a></div> <div class="up"><a href="class.ds-deque.html">Deque</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ds-deque.map" class="refentry"> <div class="refnamediv"> <h1 class="refname">Ds\Deque::map</h1> <p class="verinfo">(PECL ds >= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Deque::map</span> — <span class="dc-title">Returns the result of applying a callback to each value</span></p> </div> <div class="refsect1 description" id="refsect1-ds-deque.map-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><span class="type Ds\Deque">Ds\Deque</span></span> <span class="methodname"><strong>Ds\Deque::map</strong></span> ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span> )</div> <p class="para rdfs-comment"> Returns the result of applying a <code class="parameter">callback</code> function to each value in the deque. </p> </div> <div class="refsect1 parameters" id="refsect1-ds-deque.map-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">callback</code></dt> <dd> <p class="para"> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><span class="replaceable">callback</span></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span> )</div> </p> <p class="para"> A <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> to apply to each value in the deque. </p> <p class="para"> The callable should return what the new value will be in the new deque. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-ds-deque.map-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The result of applying a <code class="parameter">callback</code> to each value in the deque. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The values of the current instance won't be affected. </p> </p></blockquote> </div> <div class="refsect1 examples" id="refsect1-ds-deque.map-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-5227"> <p><strong>Example #1 <span class="function"><strong>Ds\Deque::map()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$deque </span><span style="color: #007700">= new \</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Deque</span><span style="color: #007700">([</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</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">$deque</span><span style="color: #007700">-></span><span style="color: #0000BB">map</span><span style="color: #007700">(function(</span><span style="color: #0000BB">$value</span><span style="color: #007700">) { return </span><span style="color: #0000BB">$value </span><span style="color: #007700">* </span><span style="color: #0000BB">2</span><span style="color: #007700">; }));<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$deque</span><span style="color: #007700">);<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\Deque Object ( [0] => 2 [1] => 4 [2] => 6 ) Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 ) </pre></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-deque.last.html">Ds\Deque::last</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-deque.merge.html">Ds\Deque::merge</a></div> <div class="up"><a href="class.ds-deque.html">Deque</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>