PHP如何使用Ds\Queue copy()函数?用法介绍

2021年3月31日16:51:00 发表评论 665 次浏览

Ds\Queue::copy()PHP中的函数用于创建特定Queue实例的浅表副本。此函数不会影响现有的Queue实例, 它只是创建Queue的浅表副本并返回它。

语法如下:

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

参数:该函数不接受任何参数。

返回值:此函数创建现有Queue实例的浅表副本并返回它。

下面的程序说明了Ds\Queue::copy()PHP中的功能:

程序1:

<?php 
  
// Declare new Queue  
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "One" );
$q ->push( "Two" );
$q ->push( "Three" );
  
// Create copy of this Queue 
// instance and print it
print_r( $q -> copy ());
  
?>

输出如下:

Ds\Queue Object
(
    [0] => One
    [1] => Two
    [2] => Three
)

程式2:

<?php 
  
// Declare new Queue  
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "Geeks" );
$q ->push( "for" );
$q ->push( "Geeks" );
  
// Create copy of this Queue 
// instance and print it
print_r( $q -> copy ());
  
?>

输出如下:

Ds\Queue Object
(
    [0] => Geeks
    [1] => for
    [2] => Geeks
)

参考:http://php.net/manual/en/ds-priorityqueue.copy.php


木子山

发表评论

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