Open In App

PHP SplPriorityQueue rewind() Function

Last Updated : 22 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The SplPriorityQueue::rewind() function is an inbuilt function in PHP which is used to rewind the iterator back to the start position.

Syntax:

void SplPriorityQueue::rewind()

Parameters: This function does not accept any parameter.

Return Value: This function does not return any value.

 

Example:

PHP




<?php
  
// Declare a class
class priorityQueue extends SplPriorityQueue {
      
    // Compare function to compare priority
    // queue elements
    public function compare($p1, $p2) {
        if ($p1 === $p2) return 0;
        return $p1 < $p2 ? -1 : 1;
    }
}
  
// Create an object of priority queue
$obj = new priorityQueue();
  
// Insert elements into the queue
$obj->insert("Geeks",2);
$obj->insert("GFG",1);
$obj->insert("G4G",3);
$obj->insert('G',4);
  
// Use rewind() function
$obj->rewind();
  
// Print the priority queue elements
var_dump($obj->current());
  
?>


Output

string(1) "G"

Reference: https://www.php.net/manual/en/splpriorityqueue.rewind.php


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads