• PHP Video Tutorials

PHP - Ds Deque apply() Function



Ds\Deque::apply() function can update all values by applying a callback function to each value.

Syntax

public void Ds\Deque::apply( callable $callback )

Ds\Deque::apply() function can update all values by applying a callback function to each value in the deque.

Ds\Deque::apply() function doesn't return any value.

Example 1

<?php 
   $deque = new \Ds\Deque([1, 2, 3, 4, 5, 6]); 
   echo("\n The elements in the deque: \n"); 
   print_r($deque);  
   
   $deque->apply(function($element) {  
      return $element * 10;  
   });  
   echo("\n The updated elements in the deque: \n"); 
   print_r($deque); 
?>

Example 2

<?php 
   $deque = new \Ds\Deque([10, 20, 30, 40, 50, 60]);  
   echo("\n The elements in the deque: \n"); 
   print_r($deque); 
   
   $deque->apply(function($element) {  
      return $element % 10;  
   }); 
   echo("\n The updated elements in the deque: \n"); 
   print_r($deque); 
?> 
php_function_reference.htm
Advertisements