PHP | Ds\Vector apply() Function Last Updated : 22 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Vector::apply() function is an inbuilt function in PHP which is used to update all values in the array by applying the callback function to each value of the vector. After this callback, all the values of the vector will get modified as defined in the callback function. Syntax: void public Ds\Vector::apply( $callback ) Parameters: This function accepts a single parameter $callback which is used to update the values in the vector. This callback function should return the value by which vector element is to be replaced. Return Value: This function does not return any value. Below programs illustrate the Ds\Vector::apply() function in PHP: Program 1: PHP <?php // Declare the callback function $callback = function($value) { return $value / 10; }; // Declare a vector $vector = new \Ds\Vector([10, 20, 30, 40, 50]); // Use apply() function to call function $vector->apply($callback); // Display the vector element print_r($vector); ?> Output: Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Program 2: PHP <?php // Declare the callback function $callback = function($value) { return $value * 5; }; // Declare a vector $vector = new \Ds\Vector([1, 2, 3, 4, 5]); // Use apply() function to call function $vector->apply($callback); // Display the vector element print_r($vector); ?> Output: Ds\Vector Object ( [0] => 5 [1] => 10 [2] => 15 [3] => 20 [4] => 25 ) Reference: http://php.net/manual/en/ds-vector.apply.php Comment More infoAdvertise with us Next Article PHP | DsSequence apply() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP | DsDeque apply() Function The Ds\Deque::apply() function is an inbuilt function in PHP which is used to update the values of Deque by performing operations as defined by the callback function. Syntax: public Ds\Deque::apply( $callback ) : void Parameters: This function accepts single parameter $callback which holds the funct 2 min read PHP | DsVector apply() Function The Ds\Vector::apply() function is an inbuilt function in PHP which is used to update all values in the array by applying the callback function to each value of the vector. After this callback, all the values of the vector will get modified as defined in the callback function. Syntax: void public Ds 2 min read PHP | DsSequence apply() Function The Ds\Sequence::apply() function is an inbuilt function in PHP which is used to updates all value of sequence by applying a callback function to each value. Syntax: void abstract public Ds\Sequence::apply ( callable $callback ) Parameter: This function accepts single parameter $callback which is us 1 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 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 copy() Function The Ds\Set::copy() function is an inbuilt function in PHP which is used to returns the copy of the set element. Syntax: Ds\Set public Ds\Set::copy( void ) Parameter: This function does not contains any parameter. Return value: It returns the copy of set elements. Below programs illustrate the Ds\Set 1 min read PHP | Ds\Vector apply() Function min read Like