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 used to apply to each value in the sequence.
Return value: This function does not return any parameters.
Below programs illustrate the Ds\Sequence::apply() function in PHP:
Program 1:
<?php // Create new sequence $seq = new \Ds\Vector([10, 20, 30, 40, 50]); // Use apply() function $seq->apply(function($val) { return $val / 5; }); // Display result print_r($seq); ?> |
Ds\Vector Object
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
)
Program 2:
<?php // Create new sequence $seq = new \Ds\Vector([2, 3, 5, 6, 8]); // Use apply() function $seq->apply(function($val) { return $val; }); // Display result var_dump($seq); ?> |
object(Ds\Vector)#1 (5) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(5)
[3]=>
int(6)
[4]=>
int(8)
}
Reference: https://www.php.net/manual/en/ds-sequence.apply.php
Recommended Posts:
- PHP | Ds\Map apply() Function
- PHP | Ds\Vector apply() Function
- PHP | Ds\Deque 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 apply css property to a child element using JQuery?
- How to dynamically create and apply CSS class in JavaScript ?
- How to get the function name inside a function in PHP ?
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.

