PHP | Ds\Map putAll() function
The Ds\Map::putAll() function is an inbuilt function in PHP, which is used to associates all key-value pairs of a traversable object or array.
Syntax:
void public Ds\Map::putAll( mixed $pairs )
Parameter: This function accepts single parameter $pairs which is the traversal object or array.
Return value: It does not return any value.
Below programs illustrate the Ds\Map::putAll() function in PHP:
Program 1:
<?php // Declare a new map $map = new \Ds\Map(); $map->putAll([ "a" => "Geeks", "b" => "for", "c" => "Geeks"]); print_r($map); // Declare a new map $map = new \Ds\Map(); $map->putAll([ "b" => "Computer", "e" => "Science", "f" => "Portal"]); print_r($map); ?> |
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => a
[value] => Geeks
)
[1] => Ds\Pair Object
(
[key] => b
[value] => for
)
[2] => Ds\Pair Object
(
[key] => c
[value] => Geeks
)
)
Ds\Map Object
(
[0] => Ds\Pair Object
(
[key] => b
[value] => Computer
)
[1] => Ds\Pair Object
(
[key] => e
[value] => Science
)
[2] => Ds\Pair Object
(
[key] => f
[value] => Portal
)
)
Program 2:
<?php // Declare a new map $map = new \Ds\Map(); $map->putAll([ "Geeks1" => "computer", "Geeks2" => "science", "Geeks3" => 5, "Geeks4" => 20 ]); var_dump($map); // Declare a new map $map = new \Ds\Map(); $map->putAll([ "x" => "A", "y" => "B", "z" => "C"]); var_dump($map); ?> |
object(Ds\Map)#1 (4) {
[0]=>
object(Ds\Pair)#2 (2) {
["key"]=>
string(6) "Geeks1"
["value"]=>
string(8) "computer"
}
[1]=>
object(Ds\Pair)#3 (2) {
["key"]=>
string(6) "Geeks2"
["value"]=>
string(7) "science"
}
[2]=>
object(Ds\Pair)#4 (2) {
["key"]=>
string(6) "Geeks3"
["value"]=>
int(5)
}
[3]=>
object(Ds\Pair)#5 (2) {
["key"]=>
string(6) "Geeks4"
["value"]=>
int(20)
}
}
object(Ds\Map)#5 (3) {
[0]=>
object(Ds\Pair)#1 (2) {
["key"]=>
string(1) "x"
["value"]=>
string(1) "A"
}
[1]=>
object(Ds\Pair)#4 (2) {
["key"]=>
string(1) "y"
["value"]=>
string(1) "B"
}
[2]=>
object(Ds\Pair)#3 (2) {
["key"]=>
string(1) "z"
["value"]=>
string(1) "C"
}
}
Reference: https://www.php.net/manual/en/ds-map.putall.php
Recommended Posts:
- IdentityHashMap putAll() Method in Java
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- p5.js | abs() function
- D3.js | d3.set.add() Function
- p5.js | sq() function
- PHP | Ds\Map xor() Function
- p5.js | day() function
- D3.js | d3.rgb() Function
- p5.js | pow() function
- D3.js | d3.sum() function
- p5.js | arc() Function
- CSS | hsl() Function
- PHP Ds\Set sum() Function
- PHP Ds\Set get() Function
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.



