PHP | Ds\Deque apply() Function Last Updated : 14 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function define the operation to be performed on each element of the Deque. Return value: This function does not return any value. Below programs illustrate the Ds\Deque::apply() function in PHP: Program 1: PHP <?php // Declare deque $deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("\nElements in the deque are\n"); // Display the deque elements print_r($deck); // Use apply() function to implement // the operation $deck->apply(function($element) { return $element * 10; }); echo("\nUpdated elements in the deque\n"); // Display the deque elements print_r($deck); ?> Output: Elements in the deque are Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Updated elements in the deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Program 2: PHP <?php // Declare deque $deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]); echo("\nElements in the deque are\n"); // Display the deque elements print_r($deck); // Use apply() function to implement // the operation $deck->apply(function($element) { return $element % 10; }); echo("\nUpdated elements in the deque\n"); // Display the deque elements print_r($deck); ?> Output: Elements in the deque are Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Updated elements in the deque Ds\Deque Object ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 ) Reference: http://php.net/manual/en/ds-deque.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_map 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 | 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 | DsDeque copy() Function The Ds\Deque::copy() function is an inbuilt function in PHP which is used to return a copy of the Deque. This will return a shallow copy of the Deque. Syntax: public Ds\Deque::copy ( void ) : Ds\Deque Parameters: This function does not contain any parameter. Return Value: This function returns a cop 2 min read PHP | DsDeque capacity() Function The Ds\Deque::capacity() function is an inbuilt function in PHP which is used to get the current capacity of the Deque. Syntax: public Ds\Deque::capacity( void ) : int Parameters: This function does not accepts any parameter. Return Value: This function returns the current capacity of the Deque. Bel 1 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 | DsDeque find() Function The Ds\Deque::find() function is an inbuilt function in PHP which is used to find the index of the element in the Deque if element found in the Deque.Syntax: public Ds\Deque::find( $value ) : mixed Parameters: This function accepts single parameter $value which holds the element whose index is to be 2 min read PHP | Ds\Deque apply() Function min read Like