Ds \ Set::__construct()函数是PHP中的内置函数,用于创建set的新实例。
用法:
Ds\Set::__construct( $values )
参数:此函数接受单个参数$values,该参数保存可遍历的对象或数组以使用初始值。
以下示例程序旨在说明PHP中的Ds \ Set::__construct()函数:
程序1:
<?php
// Declare a new set
$set = new \Ds\Set();
print_r($set);
// Declare a new set
$set = new \Ds\Set(['G', 'E', 'K', 'S']);
print_r($set);
?>
输出:
Ds\Set Object
(
)
Ds\Set Object
(
[0] => G
[1] => E
[2] => K
[3] => S
)
程序2:
<?php
// Declare a new set
$set = new \Ds\Set([2, 3, 6, 7, 8]);
var_dump($set);
// Declare a new set
$set = new \Ds\Set([2, 3, 5, 8, 9, 10]);
var_dump($set);
?>
输出:
object(Ds\Set)#1 (5) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(6)
[3]=>
int(7)
[4]=>
int(8)
}
object(Ds\Set)#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-set.construct.php
相关用法
- PHP key()用法及代码示例
- PHP pos()用法及代码示例
- PHP Ds\Set xor()用法及代码示例
- CSS rgb()用法及代码示例
- p5.js nfs()用法及代码示例
- p5.js nfp()用法及代码示例
- PHP tan( )用法及代码示例
- p5.js nfc()用法及代码示例
- PHP min( )用法及代码示例
- PHP max( )用法及代码示例
- PHP cos( )用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Ds\Set __construct() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
