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 // 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); ?> |
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 // 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); ?> |
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
Recommended Posts:
- PHP | Ds\Map apply() Function
- PHP | Ds\Vector apply() Function
- PHP | Ds\Sequence apply() Function
- JavaScript | Function Apply
- How to apply !important in CSS?
- What is the difference between call and apply in JavaScript?
- How to apply multiple transform property to an element using CSS ?
- Copy all the attributes of one element and apply them to another with JavaScript
- JavaScript | Reflect.apply() Method
- How to apply border inside a table ?
- JavaScript | handler.apply() Method
- How to apply two CSS classes to a single element ?
- How to apply style to parent if it has child with CSS?
- How to apply CSS property to an iframe ?
- How to apply colored shadow and border properties to a grayscale image?
- How to apply CSS page-break to print a table with lots of rows?
- How to apply animation in D3.js?
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

