當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Ds\Set __construct()用法及代碼示例

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



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Ds\Set __construct() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。