Open In App

PHP | Ds\Pair __construct() Function

Last Updated : 30 Jul, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Ds\Pair::__construct() function is an inbuilt function in PHP which is used to create a new instance. Syntax:
public Ds\Pair::__construct( $key, $value )
Parameters: This function accepts two parameters as mentioned above and described below:
  • $key: This parameter holds the key of the pair element.
  • $value: This parameter holds the value of the pair element.
Return Value: This function does not return any value. Below programs illustrate the Ds\Pair::__construct() function in PHP: Program 1:
Output:
Ds\Pair Object
(
    [key] => 
    [value] => 
)
Ds\Pair Object
(
    [key] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [value] => Array
        (
            [0] => Geeks
            [1] => for
            [2] => Geeks
        )

)
Program 2:
Output:
object(Ds\Pair)#1 (2) {
  ["key"]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
  ["value"]=>
  array(3) {
    [0]=>
    string(2) "10"
    [1]=>
    string(1) "2"
    [2]=>
    string(2) "30"
  }
}
Reference: https://www.php.net/manual/en/ds-pair.construct.php

Next Article

Similar Reads