PHP | Ds\Vector map() Function Last Updated : 22 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Vector::map() function is an inbuilt function in PHP which is used to return the result of a callback after applying to each value in the vector. Syntax: Ds\Vector public Ds\Vector::map( $callback ) Parameters: This function accepts single parameter $callback which is to be applied to each vector elements. Return Value: This function returns the vector after applying the callback to each value in the vector. Below programs illustrate the Ds\Vector::map() function in PHP: Program 1: PHP <?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; })); ?> Output: Ds\Vector Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 ) Program 2:This program shows the implementation of map() function which sets 1 in the vector for each element satisfying the condition in callback. PHP <?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; })); ?> Output: Ds\Vector Object ( [0] => 1 [1] => 1 [2] => 1 [3] => [4] => ) Reference: http://php.net/manual/en/ds-vector.map.php Comment More infoAdvertise with us Next Article PHP | DsMap xor() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP | DsDeque map() Function The Ds\Deque::map() function is an inbuilt function in PHP which is used to return the Deque with each element modified on the basis of operation performed as per the callback function. Syntax: public Ds\Deque::map( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback 2 min read PHP | DsVector map() Function The Ds\Vector::map() function is an inbuilt function in PHP which is used to return the result of a callback after applying to each value in the vector. Syntax: Ds\Vector public Ds\Vector::map( $callback ) Parameters: This function accepts single parameter $callback which is to be applied to each ve 2 min read PHP | DsMap xor() Function The Ds\Map::xor() function is an inbuilt function in PHP which is used to create a new map which contains the value either in the first map or second map but not both. Syntax: Ds\Map public Ds\Map::xor ( Ds\Map $map ) Parameter: This parameter holds the other map of values. Return value: It is used 2 min read PHP | DsSet xor() Function The Ds\Set::xor() function is an inbuilt function in PHP which is used to create a new set which contains the value either in the first set or second set but not both. Syntax: Ds\Set public Ds\Set::xor ( Ds\Set $set ) Parameters: This function accepts a single parameter $set which is used to hold th 2 min read PHP DsMap toArray() Function The Ds\Map::toArray() function in PHP is used to get an array generated by converting the Map instance into an Array. The resulting array is an associative array with elements as in same order as that of the specified Map instance. Syntax: array public Ds\Map::toArray ( void ) Parameter: This functi 1 min read PHP | DsMap reverse() Function The Ds/Map::reverse() function in PHP is used to in-place reverse the elements of a specified Map instance. That is, the function in-place reverses the order of elements present in the specified Map instance. Syntax: Ds\Map public Ds\Map::reverse ( int $position ) Parameter: This function does not a 2 min read PHP | Ds\Vector map() Function min read Like