Friday, January 10, 2025
Google search engine
HomeLanguagesPHP | DsSet copy() Function

PHP | Ds\Set copy() Function

The Ds\Set::copy() function is an inbuilt function in PHP which is used to returns the copy of the set element.

Syntax:

Ds\Set public Ds\Set::copy( void )

Parameter: This function does not contains any parameter.

Return value: It returns the copy of set elements.

Below programs illustrate the Ds\Set::copy() function in PHP:

Program 1:




<?php 
  
// Create new Set 
$set = new \Ds\Set([10, 15, 21, 13, 16, 18]); 
  
// Display the Set element 
print_r($set); 
  
// Use copy() function
$set->copy(); 
  
// Display the Set element 
print_r($set); 
  
?> 


Output:

Ds\Set Object
(
    [0] => 10
    [1] => 15
    [2] => 21
    [3] => 13
    [4] => 16
    [5] => 18
)
Ds\Set Object
(
    [0] => 10
    [1] => 15
    [2] => 21
    [3] => 13
    [4] => 16
    [5] => 18
)

Program 2:




<?php 
  
// Create new Set 
$set = new \Ds\Set(["Geeks", "GFG", "ABC"]); 
  
// Display the Set element 
print_r($set); 
    
// Use copy() function
$set->copy(); 
    
// Display the Set element 
print_r($set); 
    
?> 


Output:

Ds\Set Object
(
    [0] => Geeks
    [1] => GFG
    [2] => ABC
)
Ds\Set Object
(
    [0] => Geeks
    [1] => GFG
    [2] => ABC
)

Reference: http://php.net/manual/en/ds-set.copy.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments