• PHP Video Tutorials

PHP - Ds Vector map() Function



Ds\Vector::map() function can return the result of applying a callback to each value.

Syntax

public Ds\Vector Ds\Vector::map( callable $callback )

Ds\Vector::map() function can return the result of applying a callback function to each value in a vector.

Example 1

<?php 
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
  
   print_r($vector->map(function($value) {  
      return $value * 5;  
   })); 
?>

Example 2

<?php 
   $vector = new \Ds\Vector([5, 15, 25, 35, 45]); 
  
   print_r($vector->map(function($value) {  
      return $value <= 35; 
   })); 
?>
php_function_reference.htm
Advertisements