PHP Ds Queue clear()函数用法介绍

2021年3月13日17:00:18 发表评论 695 次浏览

Ds \ Queue :: clear()PHP中的函数用于清除Queue实例中的所有元素。此功能仅清除实例而不删除它。

语法如下:

void public Ds\PriorityQueue::clear ( void )

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

返回值:该函数不返回任何值。

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

程序1:

<?php 
  
// Declare new Queue 
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "One" );
$q ->push( "Two" );
$q ->push( "Three" );
  
echo "Initial Queue: \n" ;
// Display the Queue 
print_r( $q );
  
// clear the Queue 
$q ->clear();
  
echo "\nQueue after clearing:\n" ;
print_r( $q );
  
?>

输出如下:

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

Queue after clearing:
Ds\Queue Object
(
)

程式2:

<?php 
  
// Declare new Queue 
$q = new \Ds\Queue(); 
  
// Add elements to the Queue 
$q ->push( "Geeks" );
$q ->push( "for" );
$q ->push( "Geeks" );
  
echo "Initial Queue: \n" ;
// Display the Queue 
print_r( $q );
  
// clear the Queue 
$q ->clear();
  
echo "\nQueue after clearing:\n" ;
print_r( $q );
  
?>

输出如下:

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

Queue after clearing:
Ds\Queue Object
(
)

参考: http://php.net/manual/en/ds-queue.clear.php


木子山

发表评论

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