PHP | Ds Vector __construct()函数用法介绍

2021年3月10日16:22:45 发表评论 610 次浏览

Ds \ Vector :: __ construct()function是PHP中的内置函数, 用于创建新实例。

语法如下:

public Ds\Vector::__construct( $values )

参数:该函数接受单个参数$值包含可遍历的对象或数组以使用初始值。

下面的程序说明了Ds \ Vector :: __ construct()PHP中的功能:

程序1:

<?php 
    
// Declare a new Vector
$vect = new \Ds\Vector();
print_r( $vect );
   
// Declare a new set
$vect = new \Ds\Vector([ 'G' , 'E' , 'K' , 'S' ]); 
print_r( $vect );
   
?>

输出如下:

Ds\Vector Object
(
)
Ds\Vector Object
(
    [0] => G
    [1] => E
    [2] => K
    [3] => S
)

程式2:

<?php 
    
// Declare a new vector
$vect = new \Ds\Vector([2, 3, 6, 7, 8]); 
var_dump( $vect );
   
// Declare a new vector
$vect = new \Ds\Vector([2, 3, 5, 8, 9, 10]); 
var_dump( $vect );
?>

输出如下:

object(Ds\Vector)#1 (5) {
  [0]=>
  int(2)
  [1]=>
  int(3)
  [2]=>
  int(6)
  [3]=>
  int(7)
  [4]=>
  int(8)
}
object(Ds\Vector)#2 (6) {
  [0]=>
  int(2)
  [1]=>
  int(3)
  [2]=>
  int(5)
  [3]=>
  int(8)
  [4]=>
  int(9)
  [5]=>
  int(10)
}

参考: https://www.php.net/manual/en/ds-vector.construct.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: