PHP | Ds\Deque map() Function Last Updated : 14 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 which contains the callable function on the operation to be performed on each element of the Deque. Return Value: This function returns a Deque with each element modified. Below programs illustrate the Ds\Deque::map() function in PHP: Program 1: PHP <?php // Declare a Deque $deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("Elements of deque\n"); // Display the Elements of Deque print_r($deck); // Deque after mapping each value as // per in the callable function print_r($deck->map(function($element) { // performing operation on each element return $element * 10; })); ?> Output: Elements of deque Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Program 2: PHP <?php // Declare a Deque $deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]); echo("Elements of deque\n"); // Display the Elements of Deque print_r($deck); // Deque after mapping each value as // per in the callable function print_r($deck->map(function($element) { // performing operation on each element return $element / 10; })); ?> Output: Elements of deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Reference: http://php.net/manual/en/ds-deque.map.php Comment More infoAdvertise with us Next Article PHP | DsSequence map() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_queue 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 | DsSequence map() Function The Ds\Sequence::map() function is an inbuilt function in PHP which returns the result after applying callback function to each value. Syntax: Ds\Sequence abstract public Ds\Sequence::map( $callback ) Parameter: This function accepts single parameter $callback. The callback apply on each value of se 1 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 | DsDeque last() Function The Ds\Deque::last() function is an inbuilt function in PHP which is used to return the last element of Deque if Deque is not empty. Syntax: public Ds\Deque::last( void ) : mixed Parameters: This function does not accept any parameter. Return Value: This function returns the last element in the dequ 2 min read PHP | DsDeque isEmpty() Function The Ds\Deque::isEmpty() function is an inbuilt function in PHP which is used to check the Deque is empty or not. Syntax: public Ds\Deque::isEmpty( void ) : bool Parameters: This function does not accept any parameter. Return Value: This function returns true if the Deque is empty, else return false. 1 min read PHP | DsDeque get() Function The Ds\Deque::get() function is an inbuilt function in PHP which is used to return the value at the given index. Syntax: public Ds\Deque::get( $index ) : mixed Parameters: This function accepts single parameter $index which holds the index for which element is to be found. Return Value: This functio 2 min read PHP | Ds\Deque map() Function min read Like