PHP如何使用Ds PriorityQueue copy()函数?示例

2021年3月26日16:53:04 发表评论 689 次浏览

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

语法如下:

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

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

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

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

程序1:

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

输出如下:

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

程式2:

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

输出如下:

Ds\PriorityQueue 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: