Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the DS\Vector __construct() method in PHP?

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The __construct() is an built-in magic method of the DS\Vector class in PHP that’s used to construct a new instance of a vector from a traversable object or array.

Prototype

public Ds\Vector::__construct($values = ?)

Parameters

values: A traversable object or an array to use for the initial values.

Return value

It will return a new vector.

Example

<?php
$arr = new \Ds\Vector([10, 20, 30, 40, 50]);
print_r($arr);
$arr = new \Ds\Vector(['H', 'E', 'L', 'L', 'O']);
print_r($arr);
?>
Creating a traversable object and displaying it

Explanation

  • Line 3: We create a vector $arr of integer values.
  • Line 4: We print $arr.
  • Line 6: We create a vector $arr of characters.
  • Line 7: We print $arr.

RELATED TAGS

php

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring