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

PHP - Ds Vector::__construct() Function



The PHP Ds\Vector::__construct() function is used to create a new instance of a vector. This new instance refers to an object of the Ds\Vector class.

Syntax

Following is the syntax of the PHP Ds\Vector::__construct() function −

public Ds\Vector::__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\Vector::__construct() function −

<?php
   $vector = new \Ds\Vector();
   print_r($vector);
   # declare another vector
   $vector  = new \DS\Vector([10, 20, 30]);
   print_r($vector);
?>

Output

The above program produces the following output −

Ds\Vector Object
(
)
Ds\Vector Object
(
    [0] => 10
    [1] => 20
    [2] => 30
)

Example 2

Following is another example of the PHP Ds\Vector::__construct() function. We use this function to create new instances −

<?php
   $vector = new \Ds\Vector(['a', 'e', 'i']);
   print_r($vector);
   # declare another vector
   $vector  = new \DS\Vector(['a', 'e', 'i', 'o', 'u']);
   print_r($vector);
?>

Output

After executing the above program, the following output will be displayed −

Ds\Vector Object
(
    [0] => a
    [1] => e
    [2] => i
)
Ds\Vector Object
(
    [0] => a
    [1] => e
    [2] => i
    [3] => o
    [4] => u
)
php_function_reference.htm
Advertisements