PHP Ds / Deque map () function

PHP

Syntax:
public DsDeque::map ($callback): DsDeque
Parameters: This function takes one parameter, $callback, which contains the function to call for the operation performed on each Deque.Return Value:this function returns a Deque with each changed element.The following programs illustrate the Ds / Deque::map()function in PHP:Program 1: < / strong> < tr>  
// Declare Deque $deck = new DsDeque ([1, 2, 3, 4, 5, 6]); echo ( " Elements of deque " );  
// Show Deque elements print_r ( $deck );  
// Deque after matching each value as
// per in the called function print_r ( $deck -> map ( function ( $element ) { // perform an operation on each element return $element * 10; }));  
?>
Exit:
Elements of deque DsDeque Object ([0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5 [5] = > 6) DsDeque Object ([ 0] = > 10 [1] = > 20 [2] = > 30 [3] = > 40 [4] = > 50 [5] = > 60)
Program 2:  
// Declare Deque $deck = new DsDeque ([10, 20, 30, 40, 50, 60]); echo ( " Elements of deque " );  
// Show Deque elements print_r ( $deck );  
// Deque after matching each value as
// per in the called function print_r ( $deck -> map ( function ( $element ) { // perform an operation on each element return $element / 10; }));  
?>
Exit:
Elements of deque DsDeque Object ([0] = > 10 [1] = > 20 [2] = > 30 [3] = > 40 [4] = > 50 [5] = > 60) DsDeque Object ([ 0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5 [5] = > 6)
Link: http://php.net/manual/en/ds-deque.map. php



Get Solution for free from DataCamp guru