Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - Ds Map::values() Function



The PHP Ds\Map::values() function is used to retrieve the sequence of the values are of the current map. The values of the returned sequence will be in the same order as the map.

The sequence of elements in a PHP associative collection is the order in which the elements were added.

Syntax

Following is the syntax of the PHP Ds\Map::values() function −

public Ds\Map::values(): Ds\Sequence

Parameters

This function does not accept any parameter.

Return value

This function returns a sequence containing all the map values, in the same order.

Example 1

The following is the basic example of the PHP Ds\Map::values() function −

<?php  
   $map = new \Ds\Map([20, 10, 30]);
   echo "The map values are: \n";
   print_r($map);
   echo "The sequence of map values: \n";
   print_r($map->values());
?>

Output

The above program displays the following output −

The map values are:
Ds\Map Object
(
    [0] => Ds\Pair Object
        (
            [key] => 0
            [value] => 20
        )

    [1] => Ds\Pair Object
        (
            [key] => 1
            [value] => 10
        )

    [2] => Ds\Pair Object
        (
            [key] => 2
            [value] => 30
        )

)
The sequence of map values:
Ds\Vector Object
(
    [0] => 20
    [1] => 10
    [2] => 30
)

Example 2

Following is another example of the PHP Ds\Map::values() function. We use this function to retrieve the sequence of these map (["Tutorials", "Point", "India"]) elements −

<?php  
   $map = new \Ds\Map(["Tutorials", "Point", "India"]);
   echo "The map values are: \n";
   print_r($map);
   echo "The sequence of map values: \n";
   print_r($map->values());
?>

Output

After executing the above program, it will display the following output −

The map values are:
Ds\Map Object
(
    [0] => Ds\Pair Object
        (
            [key] => 0
            [value] => Tutorials
        )

    [1] => Ds\Pair Object
        (
            [key] => 1
            [value] => Point
        )

    [2] => Ds\Pair Object
        (
            [key] => 2
            [value] => India
        )

)
The sequence of map values:
Ds\Vector Object
(
    [0] => Tutorials
    [1] => Point
    [2] => India
)
php_function_reference.htm
Advertisements