PHP - Ds Pair::__construct() Function
The PHP Ds\Pair::__construct() function is used to create a new instance of a pair. This new instance refers to an object of the Ds\Pair class.
Syntax
Following is the syntax of the PHP Ds\Pair::__construct() function −
public Ds\Pair::__construct(mixed $values = ?)
Parameters
Following is the parameter of this function −
- values − A traversable object or an array to use for the initial values.
Return value
This function does not return any value.
Example 1
The following is the basic example of the PHP Ds\Pair::__construct() function −
<?php $pair = new \Ds\Pair(); print_r($pair); # declare another pair $pair = new \DS\Pair(['a', 'b', 'c'],[10, 20, 30]); print_r($pair); ?>
Output
The above program produces the following output −
Ds\Pair Object
(
[key] =>
[value] =>
)
Ds\Pair Object
(
[key] => Array
(
[0] => a
[1] => b
[2] => c
)
[value] => Array
(
[0] => 10
[1] => 20
[2] => 30
)
)
Example 2
Following is another example of the PHP Ds\Pair::__construct() function. We use this function to create new instances −
<?php $pair = new \Ds\Pair([1, 2, 3],['a', 'e', 'i']); print_r($pair); # declare another pair $pair = new \DS\Pair([1, 2, 3, 4, 5], ['a', 'e', 'i', 'o', 'u']); print_r($pair); ?>
Output
After executing the above program, the following output will be displayed −
Ds\Pair Object
(
[key] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[value] => Array
(
[0] => a
[1] => e
[2] => i
)
)
Ds\Pair Object
(
[key] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
[value] => Array
(
[0] => a
[1] => e
[2] => i
[3] => o
[4] => u
)
)
php_function_reference.htm
Advertisements