Ds \ Vector::map()函数是PHP中的内置函数,在应用于向量中的每个值之后,该函数用于返回回调的结果。
用法:
Ds\Vector public Ds\Vector::map( $callback )
参数:该函数接受将应用于每个向量元素的单个参数$callback。
返回值:将回调应用于向量中的每个值之后,此函数将返回向量。
以下示例程序旨在说明PHP中的Ds \ Vector::map()函数:
程序1:
<?php
// Create new Vector
$vector = new \Ds\Vector([1, 2, 3, 4, 5]);
// Display the Vector element after
// applying the callback function
print_r($vector->map(function($value) {
return $value * 10;
}));
?>输出:
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
程序2:该程序显示了map()函数的实现,该函数针对满足回调条件的每个元素在向量中设置1。
<?php
// Create new Vector
$vector = new \Ds\Vector([10, 20, 30, 40, 50]);
// Display the Vector element after
// applying the callback function
print_r($vector->map(function($value) {
return $value <= 30;
}));
?>输出:
Ds\Vector Object
(
[0] => 1
[1] => 1
[2] => 1
[3] =>
[4] =>
)
参考: http://php.net/manual/en/ds-vector.map.php
相关用法
- p5.js str()用法及代码示例
- p5.js min()用法及代码示例
- PHP end()用法及代码示例
- PHP sin( )用法及代码示例
- PHP cos( )用法及代码示例
- p5.js hue()用法及代码示例
- PHP pos()用法及代码示例
- p5.js hex()用法及代码示例
- p5.js red()用法及代码示例
- p5.js tan()用法及代码示例
- p5.js log()用法及代码示例
- p5.js sin()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Vector map() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
