Ds \ PriorityQueue :: clear()PHP中的函数用于清除PriorityQueue实例中的所有元素。此功能仅清除实例而不删除它。
语法如下:
void public Ds\PriorityQueue::clear ( void )
参数:该函数不接受任何参数。
返回值:该函数不返回任何值。
下面的程序说明了Ds \ PriorityQueue :: clear()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);
echo "Initial PriorityQueue: \n" ;
// Display the PriorityQueue
print_r( $pq );
// clear the PriorityQueue
$pq ->clear();
echo "\nPriorityQueue after clearing:\n" ;
print_r( $pq );
?>
输出如下:
Initial PriorityQueue:
Ds\PriorityQueue Object
(
[0] => Three
[1] => Two
[2] => One
)
PriorityQueue after clearing:
Ds\PriorityQueue Object
(
)
程式2:
<?php
// Declare new PriorityQueue
$pq = new \Ds\PriorityQueue();
// Add elements to the PriorityQueue
$pq ->push( "Geeks" , 10);
$pq ->push( "for" , 20);
$pq ->push( "Geeks" , 30);
echo "Initial PriorityQueue: \n" ;
// Display the PriorityQueue
print_r( $pq );
// clear the PriorityQueue
$pq ->clear();
echo "\nPriorityQueue after clearing:\n" ;
print_r( $pq );
?>
输出如下:
Initial PriorityQueue:
Ds\PriorityQueue Object
(
[0] => Geeks
[1] => for
[2] => Geeks
)
PriorityQueue after clearing:
Ds\PriorityQueue Object
(
)
参考: http://php.net/manual/en/ds-priorityqueue.clear.php