<?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 => 'zh', ), 'this' => array ( 0 => 'ds-set.map.php', 1 => 'Ds\\Set::map', 2 => 'Returns the result of applying a callback to each value', ), 'up' => array ( 0 => 'class.ds-set.php', 1 => 'Ds\\Set', ), 'prev' => array ( 0 => 'ds-set.last.php', 1 => 'Ds\\Set::last', ), 'next' => array ( 0 => 'ds-set.merge.php', 1 => 'Ds\\Set::merge', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ds/ds/set/map.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <div id="ds-set.map" class="refentry"> <div class="refnamediv"> <h1 class="refname">Ds\Set::map</h1> <p class="verinfo">(PECL ds >= 1.2.7)</p><p class="refpurpose"><span class="refname">Ds\Set::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-set.map-description"> <h3 class="title">说明</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>Ds\Set::map</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><a href="class.ds-set.php" class="type Ds\Set">Ds\Set</a></span></div> <p class="para rdfs-comment"> Returns the result of applying a <code class="parameter">callback</code> function to each value in the set. </p> </div> <div class="refsect1 parameters" id="refsect1-ds-set.map-parameters"> <h3 class="title">参数</h3> <dl> <dt><code class="parameter">callback</code></dt> <dd> <p class="para"> The callback to apply to each value in the set must have the following signature: <div class="methodsynopsis dc-description"><span class="methodname"><span class="replaceable">callback</span></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div> </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-ds-set.map-returnvalues"> <h3 class="title">返回值</h3> <p class="para"> Returns a new <span class="classname"><a href="class.ds-set.php" class="classname">Ds\Set</a></span> instance where each value is the result of applying the <code class="parameter">callback</code> to each value of the set. </p> </div> <div class="refsect1 examples" id="refsect1-ds-set.map-examples"> <h3 class="title">示例</h3> <div class="example" id="example-4411"> <p><strong>示例 #1 <span class="methodname"><strong>Ds\Set::map()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$set </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Ds\Set</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">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$set</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">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$set</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>以上示例的输出类似于:</p></div> <div class="example-contents screen"> <div class="examplescode"><pre class="examplescode">object(Ds\Set)#3 (3) { [0]=> int(2) [1]=> int(4) [2]=> int(6) } object(Ds\Set)#1 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }</pre> </div> </div> </div> </div> </div><?php manual_footer($setup); ?>